Package org.onlab.util
Class BoundedThreadPool
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- org.onlab.util.BoundedThreadPool
-
- All Implemented Interfaces:
java.util.concurrent.Executor,java.util.concurrent.ExecutorService
public final class BoundedThreadPool extends java.util.concurrent.ThreadPoolExecutorImplementation 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
java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterExecute(java.lang.Runnable r, java.lang.Throwable t)protected voidbeforeExecute(java.lang.Thread t, java.lang.Runnable r)voidexecute(java.lang.Runnable command)static BoundedThreadPoolnewFixedThreadPool(int numberOfThreads, java.util.concurrent.ThreadFactory threadFactory)Returns a fixed-size, bounded executor service.static BoundedThreadPoolnewSingleThreadExecutor(java.util.concurrent.ThreadFactory threadFactory)Returns a single-thread, bounded executor service.java.util.concurrent.Future<?>submit(java.lang.Runnable task)<T> java.util.concurrent.Future<T>submit(java.lang.Runnable task, T result)<T> java.util.concurrent.Future<T>submit(java.util.concurrent.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
-
-
-
-
Method Detail
-
newSingleThreadExecutor
public static BoundedThreadPool newSingleThreadExecutor(java.util.concurrent.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, java.util.concurrent.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 java.util.concurrent.Future<?> submit(java.lang.Runnable task)
- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin classjava.util.concurrent.AbstractExecutorService
-
submit
public <T> java.util.concurrent.Future<T> submit(java.lang.Runnable task, T result)- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin classjava.util.concurrent.AbstractExecutorService
-
execute
public void execute(java.lang.Runnable command)
- Specified by:
executein interfacejava.util.concurrent.Executor- Overrides:
executein classjava.util.concurrent.ThreadPoolExecutor
-
submit
public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin classjava.util.concurrent.AbstractExecutorService
-
beforeExecute
protected void beforeExecute(java.lang.Thread t, java.lang.Runnable r)- Overrides:
beforeExecutein classjava.util.concurrent.ThreadPoolExecutor
-
afterExecute
protected void afterExecute(java.lang.Runnable r, java.lang.Throwable t)- Overrides:
afterExecutein classjava.util.concurrent.ThreadPoolExecutor
-
-