public class CountingThreadPoolExecutor
extends java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor which keeps track of the number of spawned
tasks to allow clients to await their completion.java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy| Modifier and Type | Field and Description |
|---|---|
protected java.lang.Throwable |
exception |
protected static Logger |
logger |
protected CountLatch |
numRunningTasks |
| Constructor and Description |
|---|
CountingThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterExecute(java.lang.Runnable r,
java.lang.Throwable t) |
void |
awaitCompletion()
Awaits the completion of all spawned tasks.
|
void |
awaitCompletion(long timeout,
java.util.concurrent.TimeUnit unit)
Awaits the completion of all spawned tasks.
|
void |
execute(java.lang.Runnable command) |
java.lang.Throwable |
getException()
Returns the exception thrown during task execution (if any).
|
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, 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, toStringprotected static final Logger logger
protected final CountLatch numRunningTasks
protected volatile java.lang.Throwable exception
public CountingThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue)
public void execute(java.lang.Runnable command)
execute in interface java.util.concurrent.Executorexecute in class java.util.concurrent.ThreadPoolExecutorprotected void afterExecute(java.lang.Runnable r,
java.lang.Throwable t)
afterExecute in class java.util.concurrent.ThreadPoolExecutorpublic void awaitCompletion()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic void awaitCompletion(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic java.lang.Throwable getException()