Package org.onlab.util
Class BoundedThreadPool
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- org.onlab.util.BoundedThreadPool
-
- All Implemented Interfaces:
Executor
,ExecutorService
public final class BoundedThreadPool extends ThreadPoolExecutor
Implementation of ThreadPoolExecutor that bounds the work queue.When a new job would exceed the queue bound, the job is run on the caller's thread rather than on a thread from the pool.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterExecute(Runnable r, Throwable t)
protected void
beforeExecute(Thread t, Runnable r)
void
execute(Runnable command)
static BoundedThreadPool
newFixedThreadPool(int numberOfThreads, ThreadFactory threadFactory)
Returns a fixed-size, bounded executor service.static BoundedThreadPool
newSingleThreadExecutor(ThreadFactory threadFactory)
Returns a single-thread, bounded executor service.Future<?>
submit(Runnable task)
<T> Future<T>
submit(Runnable task, T result)
<T> Future<T>
submit(Callable<T> task)
-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toString
-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor
-
-
-
-
Method Detail
-
newSingleThreadExecutor
public static BoundedThreadPool newSingleThreadExecutor(ThreadFactory threadFactory)
Returns a single-thread, bounded executor service.- Parameters:
threadFactory
- thread factory for the worker thread.- Returns:
- the bounded thread pool
-
newFixedThreadPool
public static BoundedThreadPool newFixedThreadPool(int numberOfThreads, ThreadFactory threadFactory)
Returns a fixed-size, bounded executor service.- Parameters:
numberOfThreads
- number of threads in the poolthreadFactory
- thread factory for the worker threads.- Returns:
- the bounded thread pool
-
submit
public Future<?> submit(Runnable task)
- Specified by:
submit
in interfaceExecutorService
- Overrides:
submit
in classAbstractExecutorService
-
submit
public <T> Future<T> submit(Runnable task, T result)
- Specified by:
submit
in interfaceExecutorService
- Overrides:
submit
in classAbstractExecutorService
-
execute
public void execute(Runnable command)
- Specified by:
execute
in interfaceExecutor
- Overrides:
execute
in classThreadPoolExecutor
-
submit
public <T> Future<T> submit(Callable<T> task)
- Specified by:
submit
in interfaceExecutorService
- Overrides:
submit
in classAbstractExecutorService
-
beforeExecute
protected void beforeExecute(Thread t, Runnable r)
- Overrides:
beforeExecute
in classThreadPoolExecutor
-
afterExecute
protected void afterExecute(Runnable r, Throwable t)
- Overrides:
afterExecute
in classThreadPoolExecutor
-
-