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 voidafterExecute(Runnable r, Throwable t)protected voidbeforeExecute(Thread t, Runnable r)voidexecute(Runnable command)static BoundedThreadPoolnewFixedThreadPool(int numberOfThreads, ThreadFactory threadFactory)Returns a fixed-size, bounded executor service.static BoundedThreadPoolnewSingleThreadExecutor(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:
submitin interfaceExecutorService- Overrides:
submitin classAbstractExecutorService
-
submit
public <T> Future<T> submit(Runnable task, T result)
- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classAbstractExecutorService
-
execute
public void execute(Runnable command)
- Specified by:
executein interfaceExecutor- Overrides:
executein classThreadPoolExecutor
-
submit
public <T> Future<T> submit(Callable<T> task)
- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classAbstractExecutorService
-
beforeExecute
protected void beforeExecute(Thread t, Runnable r)
- Overrides:
beforeExecutein classThreadPoolExecutor
-
afterExecute
protected void afterExecute(Runnable r, Throwable t)
- Overrides:
afterExecutein classThreadPoolExecutor
-
-