public class LoggingScheduledExecutor extends ScheduledThreadPoolExecutor
ThreadPoolExecutor.afterExecute(java.lang.Runnable, java.lang.Throwable)
and ScheduledThreadPoolExecutor.decorateTask(java.lang.Runnable, java.util.concurrent.RunnableScheduledFuture<V>) methods.
Reasoning is given tasks to ScheduledThreadPoolExecutor stops silently if there is an
execution exception.
Note: Task decoration is only needed to call given tasks toString methods.
Remove on cancel: To prevent running into an accumulation of cancelled task which can cause gc related problems (e.g. transactions in combination with LockResource eviction), it is best that tasks are removed from the scheduler on cancellation.
In Java 7+ the there is a method ScheduledThreadPoolExecutor#setRemoveOnCancelPolicy(boolean)
which removes the runnable on cancellation. Removal of tasks is done in logarithmic time
(see ScheduledThreadPoolExecutor.DelayedWorkQueue.indexOf where there is a direct lookup
instead of a linear scan over the queue).
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy| Constructor and Description |
|---|
LoggingScheduledExecutor(ILogger logger,
int corePoolSize,
ThreadFactory threadFactory) |
LoggingScheduledExecutor(ILogger logger,
int corePoolSize,
ThreadFactory threadFactory,
RejectedExecutionHandler handler) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterExecute(Runnable runnable,
Throwable throwable) |
void |
notifyShutdownInitiated() |
decorateTask, decorateTask, execute, getContinueExistingPeriodicTasksAfterShutdownPolicy, getExecuteExistingDelayedTasksAfterShutdownPolicy, getQueue, getRemoveOnCancelPolicy, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, setContinueExistingPeriodicTasksAfterShutdownPolicy, setExecuteExistingDelayedTasksAfterShutdownPolicy, setRemoveOnCancelPolicy, shutdown, shutdownNow, submit, submit, submitallowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, terminated, toStringinvokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskForclone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitawaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminatedpublic LoggingScheduledExecutor(ILogger logger, int corePoolSize, ThreadFactory threadFactory)
public LoggingScheduledExecutor(ILogger logger, int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler)
protected void afterExecute(Runnable runnable, Throwable throwable)
afterExecute in class ThreadPoolExecutorpublic void notifyShutdownInitiated()
Copyright © 2019 Hazelcast, Inc.. All rights reserved.