Package pl.morgwai.base.utils.concurrent
Class ScheduledTaskTrackingThreadPoolExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- java.util.concurrent.ScheduledThreadPoolExecutor
-
- pl.morgwai.base.utils.concurrent.ScheduledTaskTrackingThreadPoolExecutor
-
- All Implemented Interfaces:
Executor,ExecutorService,ScheduledExecutorService,TaskTrackingExecutor,TaskTrackingExecutor.TaskTrackingExecutorDecorator.HookableExecutor
public class ScheduledTaskTrackingThreadPoolExecutor extends ScheduledThreadPoolExecutor implements TaskTrackingExecutor, TaskTrackingExecutor.TaskTrackingExecutorDecorator.HookableExecutor
AScheduledThreadPoolExecutorthat is also aTaskTrackingExecutor. Decorates scheduled items withScheduledTaskTrackingThreadPoolExecutor.ScheduledExecution, so that the original tasks can be obtained from the result oftryForceTerminate().NOTE: due to the design of
task decorating in ScheduledThreadPoolExecutorthis class is extremely slow in case of a large number of very tiny tasks. See the comment with an explanation in the source.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classScheduledTaskTrackingThreadPoolExecutor.ScheduledExecution<V>Decorates aRunnableScheduledFutureto allow to obtain the original scheduled task.-
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.ForcedTerminationAftermath, TaskTrackingExecutor.TaskTrackingExecutorDecorator
-
-
Constructor Summary
Constructors Constructor Description ScheduledTaskTrackingThreadPoolExecutor(int corePoolSize)ScheduledTaskTrackingThreadPoolExecutor(int corePoolSize, RejectedExecutionHandler handler)ScheduledTaskTrackingThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory)ScheduledTaskTrackingThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler)
-
Method Summary
-
Methods inherited from class java.util.concurrent.ScheduledThreadPoolExecutor
execute, getContinueExistingPeriodicTasksAfterShutdownPolicy, getExecuteExistingDelayedTasksAfterShutdownPolicy, getQueue, getRemoveOnCancelPolicy, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, setContinueExistingPeriodicTasksAfterShutdownPolicy, setExecuteExistingDelayedTasksAfterShutdownPolicy, setRemoveOnCancelPolicy, shutdown, shutdownNow, submit, submit, submit
-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, terminated, toString
-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor
-
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
-
ScheduledTaskTrackingThreadPoolExecutor
public ScheduledTaskTrackingThreadPoolExecutor(int corePoolSize)
-
ScheduledTaskTrackingThreadPoolExecutor
public ScheduledTaskTrackingThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory)
-
ScheduledTaskTrackingThreadPoolExecutor
public ScheduledTaskTrackingThreadPoolExecutor(int corePoolSize, RejectedExecutionHandler handler)
-
ScheduledTaskTrackingThreadPoolExecutor
public ScheduledTaskTrackingThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler)
-
-
Method Detail
-
tryForceTerminate
public TaskTrackingExecutor.ForcedTerminationAftermath tryForceTerminate()
Description copied from interface:TaskTrackingExecutorCallsExecutorService.shutdownNow()and returns an object containing aListof tasks, that were still running right before the call. The returned object also contains theListof tasks returned byExecutorService.shutdownNow()itself.- Specified by:
tryForceTerminatein 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
-
decorateTask
protected <V> ScheduledTaskTrackingThreadPoolExecutor.ScheduledExecution<V> decorateTask(Runnable task, RunnableScheduledFuture<V> scheduledExecution)
DecoratestaskusingScheduledTaskTrackingThreadPoolExecutor.ScheduledExecution.- Overrides:
decorateTaskin classScheduledThreadPoolExecutor
-
decorateTask
protected <V> ScheduledTaskTrackingThreadPoolExecutor.ScheduledExecution<V> decorateTask(Callable<V> task, RunnableScheduledFuture<V> scheduledExecution)
DecoratestaskusingScheduledTaskTrackingThreadPoolExecutor.ScheduledExecution.- Overrides:
decorateTaskin classScheduledThreadPoolExecutor
-
-