Package pl.morgwai.base.utils.concurrent
Class TaskTrackingThreadPoolExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- pl.morgwai.base.utils.concurrent.TaskTrackingThreadPoolExecutor
-
- All Implemented Interfaces:
Executor,ExecutorService,TaskTrackingExecutor,TaskTrackingExecutor.TaskTrackingExecutorDecorator.HookableExecutor
public class TaskTrackingThreadPoolExecutor extends ThreadPoolExecutor implements TaskTrackingExecutor, TaskTrackingExecutor.TaskTrackingExecutorDecorator.HookableExecutor
TaskTrackingExecutorbased on aThreadPoolExecutor.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
-
Nested classes/interfaces inherited from interface pl.morgwai.base.utils.concurrent.TaskTrackingExecutor
TaskTrackingExecutor.TaskTrackingExecutorDecorator
-
-
Constructor Summary
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAfterExecuteHook(BiConsumer<Runnable,Throwable> hook)Adds hook to be executed inafterExecute(Runnable, Throwable).voidaddBeforeExecuteHook(BiConsumer<Thread,Runnable> hook)Addshookto be executed inbeforeExecute(Thread, Runnable).protected voidafterExecute(Runnable task, Throwable error)Executes alladdAfterExecuteHook(BiConsumer)added hooks} in the order they were added.protected voidbeforeExecute(Thread worker, Runnable task)Executes alladded hooksin the reverse order they were added.List<Runnable>getRunningTasks()Returns aListof tasks currently being run by the workerThreads.-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, execute, 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, submit, submit, submit
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit
-
Methods inherited from interface pl.morgwai.base.utils.concurrent.TaskTrackingExecutor
awaitTermination, toAwaitableOfEnforcedTermination, toAwaitableOfTermination
-
-
-
-
Constructor Detail
-
TaskTrackingThreadPoolExecutor
public TaskTrackingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler)Callssuperand sets upTaskTrackingExecutor.TaskTrackingExecutorDecorator.
-
TaskTrackingThreadPoolExecutor
public TaskTrackingThreadPoolExecutor(int poolSize)
-
TaskTrackingThreadPoolExecutor
public TaskTrackingThreadPoolExecutor(int poolSize, ThreadFactory threadFactory)
-
TaskTrackingThreadPoolExecutor
public TaskTrackingThreadPoolExecutor(int poolSize, int queueSize)
-
TaskTrackingThreadPoolExecutor
public TaskTrackingThreadPoolExecutor(int poolSize, int queueSize, ThreadFactory threadFactory)
-
TaskTrackingThreadPoolExecutor
public TaskTrackingThreadPoolExecutor(int poolSize, int queueSize, RejectedExecutionHandler handler)
-
TaskTrackingThreadPoolExecutor
public TaskTrackingThreadPoolExecutor(int poolSize, int queueSize, ThreadFactory threadFactory, RejectedExecutionHandler handler)
-
TaskTrackingThreadPoolExecutor
public TaskTrackingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue)Callssuperand sets upTaskTrackingExecutor.TaskTrackingExecutorDecorator.
-
TaskTrackingThreadPoolExecutor
public TaskTrackingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory)Callssuperand sets upTaskTrackingExecutor.TaskTrackingExecutorDecorator.
-
TaskTrackingThreadPoolExecutor
public TaskTrackingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler)Callssuperand sets upTaskTrackingExecutor.TaskTrackingExecutorDecorator.
-
-
Method Detail
-
getRunningTasks
public List<Runnable> getRunningTasks()
Description copied from interface:TaskTrackingExecutorReturns aListof tasks currently being run by the workerThreads. Unless stated otherwise by an implementing class, the result may be a subject to all kind of races and thus may sometimes not even be fully consistent with any point in the past. This method is intended for spotting long-running or stuck tasks or for general overview of types of tasks being executed.- Specified by:
getRunningTasksin interfaceTaskTrackingExecutor
-
addBeforeExecuteHook
public void addBeforeExecuteHook(BiConsumer<Thread,Runnable> hook)
Addshookto be executed inbeforeExecute(Thread, Runnable).- Specified by:
addBeforeExecuteHookin interfaceTaskTrackingExecutor.TaskTrackingExecutorDecorator.HookableExecutor
-
beforeExecute
protected final void beforeExecute(Thread worker, Runnable task)
Executes alladded hooksin the reverse order they were added.- Overrides:
beforeExecutein classThreadPoolExecutor
-
addAfterExecuteHook
public void addAfterExecuteHook(BiConsumer<Runnable,Throwable> hook)
Adds hook to be executed inafterExecute(Runnable, Throwable).- Specified by:
addAfterExecuteHookin interfaceTaskTrackingExecutor.TaskTrackingExecutorDecorator.HookableExecutor
-
afterExecute
protected final void afterExecute(Runnable task, Throwable error)
Executes alladdAfterExecuteHook(BiConsumer)added hooks} in the order they were added.- Overrides:
afterExecutein classThreadPoolExecutor
-
-