public class LoggingScheduledThreadPoolExecutor
extends java.util.concurrent.ScheduledThreadPoolExecutor
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 boolean |
continueRegularAfterException
Whether regular executions should continue even in case of exceptions.
|
protected java.util.logging.Logger |
logger
The logger for logging unhandled results, Exception, RuntimeException
or Error.
|
| Constructor and Description |
|---|
LoggingScheduledThreadPoolExecutor(int corePoolSize,
Adept2ThreadFactory threadFactory,
boolean continueRegularAfterException)
Creates a new
LoggingScheduledThreadPoolExecutor with the designated core pool
size and thread factory also providing the logger. |
LoggingScheduledThreadPoolExecutor(int corePoolSize,
Adept2ThreadFactory threadFactory,
java.util.concurrent.RejectedExecutionHandler handler,
boolean continueRegularAfterException)
Creates a new
LoggingScheduledThreadPoolExecutor with the designated core pool
size, rejected execution handler and thread factory also providing the logger. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterExecute(java.lang.Runnable r,
java.lang.Throwable t) |
protected void |
beforeExecute(java.lang.Thread t,
java.lang.Runnable r) |
protected <V> java.util.concurrent.RunnableScheduledFuture<V> |
decorateTask(java.util.concurrent.Callable<V> callable,
java.util.concurrent.RunnableScheduledFuture<V> task) |
protected <V> java.util.concurrent.RunnableScheduledFuture<V> |
decorateTask(java.lang.Runnable runnable,
java.util.concurrent.RunnableScheduledFuture<V> task) |
void |
execute(java.lang.Runnable command,
boolean logException)
Calls
ScheduledThreadPoolExecutor.execute(Runnable) and optionally wraps the runnable to catch and log an
occurring runtime exception and virtual machine error. |
<V> java.util.concurrent.ScheduledFuture<V> |
schedule(java.util.concurrent.Callable<V> callable,
long delay,
java.util.concurrent.TimeUnit unit,
boolean logException)
Calls
ScheduledThreadPoolExecutor.schedule(Callable, long, TimeUnit) and optionally wraps the callable to catch
and log an occurred exception. |
java.util.concurrent.ScheduledFuture<?> |
schedule(java.lang.Runnable command,
long delay,
java.util.concurrent.TimeUnit unit,
boolean logException,
boolean rethrowException)
Calls
ScheduledThreadPoolExecutor.schedule(Runnable, long, TimeUnit) and optionally wraps the runnable to log an
occurring runtime exception and virtual machine error. |
java.util.concurrent.ScheduledFuture<?> |
scheduleAtFixedRate(java.lang.Runnable command,
long initialDelay,
long period,
java.util.concurrent.TimeUnit unit) |
java.util.concurrent.ScheduledFuture<?> |
scheduleWithFixedDelay(java.lang.Runnable command,
long initialDelay,
long delay,
java.util.concurrent.TimeUnit unit) |
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task,
boolean logException)
Calls
ScheduledThreadPoolExecutor.submit(Callable) and optionally wraps the callable to catch and log an occurred
exception. |
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task,
boolean logException,
boolean rethrowException)
Calls
ScheduledThreadPoolExecutor.submit(Runnable) and optionally wraps the runnable to log an occurring
exception. |
<T> java.util.concurrent.Future<T> |
submit(java.lang.Runnable task,
T result,
boolean logException)
Calls
ScheduledThreadPoolExecutor.submit(Runnable, Object) and optionally wraps the runnable to log an occurring
exception. |
protected <V> java.util.concurrent.Callable<V> |
wrapCallable(java.util.concurrent.Callable<V> command,
boolean loggingRequested,
boolean rethrow)
Wraps the designated command by a callable catching and logging an occurred exception and
optionally rethrowing it to provide it via the returned callable.
|
protected java.lang.Runnable |
wrapRunnable(java.lang.Runnable command,
boolean loggingRequested,
boolean rethrow)
Wraps the designated command by a runnable logging runtime exceptions and virtual machine
errors instead of forwarding them if requested.
|
execute, getContinueExistingPeriodicTasksAfterShutdownPolicy, getExecuteExistingDelayedTasksAfterShutdownPolicy, getQueue, getRemoveOnCancelPolicy, schedule, schedule, setContinueExistingPeriodicTasksAfterShutdownPolicy, setExecuteExistingDelayedTasksAfterShutdownPolicy, setRemoveOnCancelPolicy, shutdown, shutdownNow, submit, submit, submitallowCoreThreadTimeOut, 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, toStringinvokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskForprotected final java.util.logging.Logger logger
protected final boolean continueRegularAfterException
public LoggingScheduledThreadPoolExecutor(int corePoolSize,
Adept2ThreadFactory threadFactory,
boolean continueRegularAfterException)
LoggingScheduledThreadPoolExecutor with the designated core pool
size and thread factory also providing the logger. Optionally regular scheduled tasks
(ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit)
and
ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit)
may be set to log runtime exceptions and virtual machine errors and continue regular execution
instead of failing and stopping.corePoolSize - The number of threads to keep in the pool, even if they are idle.threadFactory - The factory to use when the executor creates a new thread and which
provides the logger for unhandled results and exceptions.continueRegularAfterException - Whether regular executions should continue even in case of
runtime exceptions and virtual machine errors. These exceptions will be logged.ScheduledThreadPoolExecutor.ScheduledThreadPoolExecutor(int,
java.util.concurrent.ThreadFactory)public LoggingScheduledThreadPoolExecutor(int corePoolSize,
Adept2ThreadFactory threadFactory,
java.util.concurrent.RejectedExecutionHandler handler,
boolean continueRegularAfterException)
LoggingScheduledThreadPoolExecutor with the designated core pool
size, rejected execution handler and thread factory also providing the logger. Optionally
regular scheduled tasks
(ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit)
and
ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit)
may be set to log runtime exceptions and virtual machine errors and continue regular execution
instead of failing and stopping.corePoolSize - The number of threads to keep in the pool, even if they are idle.threadFactory - The factory to use when the executor creates a new thread and which
provides the logger for unhandled results and exceptions.handler - The handler to use when execution is blocked.continueRegularAfterException - Whether regular executions should continue even in case of
runtime exceptions and virtual machine errors. These exceptions will be logged.ScheduledThreadPoolExecutor.ScheduledThreadPoolExecutor(int,
java.util.concurrent.ThreadFactory, RejectedExecutionHandler)public java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command,
long delay,
java.util.concurrent.TimeUnit unit,
boolean logException,
boolean rethrowException)
ScheduledThreadPoolExecutor.schedule(Runnable, long, TimeUnit) and optionally wraps the runnable to log an
occurring runtime exception and virtual machine error. This will be provided via the returned
future if rethrown. If you are about to check the returned future, you should let the runtime
exception/virtual machine error be rethrown.logException - Whether to log an occurred runtime exception/virtual machine error.rethrowException - Whether to rethrow the logged runtime exception/virtual machine error.
This parameter will be ignored if logException is false.public <V> java.util.concurrent.ScheduledFuture<V> schedule(java.util.concurrent.Callable<V> callable,
long delay,
java.util.concurrent.TimeUnit unit,
boolean logException)
ScheduledThreadPoolExecutor.schedule(Callable, long, TimeUnit) and optionally wraps the callable to catch
and log an occurred exception. The exception will always be provided via the designated
callable and the returned future.logException - Whether to additionally log an occurred exception.public java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate(java.lang.Runnable command,
long initialDelay,
long period,
java.util.concurrent.TimeUnit unit)
scheduleAtFixedRate in interface java.util.concurrent.ScheduledExecutorServicescheduleAtFixedRate in class java.util.concurrent.ScheduledThreadPoolExecutorpublic java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay(java.lang.Runnable command,
long initialDelay,
long delay,
java.util.concurrent.TimeUnit unit)
scheduleWithFixedDelay in interface java.util.concurrent.ScheduledExecutorServicescheduleWithFixedDelay in class java.util.concurrent.ScheduledThreadPoolExecutorpublic void execute(java.lang.Runnable command,
boolean logException)
ScheduledThreadPoolExecutor.execute(Runnable) and optionally wraps the runnable to catch and log an
occurring runtime exception and virtual machine error. Since there is no one expecting the
exception, it will not be rethrown after logging.logException - Whether to additionally log an occurred runtime exception/virtual machine
error.public java.util.concurrent.Future<?> submit(java.lang.Runnable task,
boolean logException,
boolean rethrowException)
ScheduledThreadPoolExecutor.submit(Runnable) and optionally wraps the runnable to log an occurring
exception. The exception will be provided via the returned future if rethrown. If you are about
to check the returned future, you should let the exception be rethrown.logException - Whether to log an occurred exception.rethrowException - Whether to rethrow the logged exception. This will be ignored if
logException is false.public <T> java.util.concurrent.Future<T> submit(java.lang.Runnable task,
T result,
boolean logException)
ScheduledThreadPoolExecutor.submit(Runnable, Object) and optionally wraps the runnable to log an occurring
exception. The exception will always be provided via the returned future.logException - Whether to additionally log an occurred exception.public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task,
boolean logException)
ScheduledThreadPoolExecutor.submit(Callable) and optionally wraps the callable to catch and log an occurred
exception. The exception will always be provided via the returned callable.logException - Whether to additionally log an occurred exception.protected <V> java.util.concurrent.RunnableScheduledFuture<V> decorateTask(java.lang.Runnable runnable,
java.util.concurrent.RunnableScheduledFuture<V> task)
decorateTask in class java.util.concurrent.ScheduledThreadPoolExecutorprotected <V> java.util.concurrent.RunnableScheduledFuture<V> decorateTask(java.util.concurrent.Callable<V> callable,
java.util.concurrent.RunnableScheduledFuture<V> task)
decorateTask in class java.util.concurrent.ScheduledThreadPoolExecutorprotected void beforeExecute(java.lang.Thread t,
java.lang.Runnable r)
beforeExecute in class java.util.concurrent.ThreadPoolExecutorprotected void afterExecute(java.lang.Runnable r,
java.lang.Throwable t)
afterExecute in class java.util.concurrent.ThreadPoolExecutorprotected java.lang.Runnable wrapRunnable(java.lang.Runnable command,
boolean loggingRequested,
boolean rethrow)
command - The command which to wrap.loggingRequested - Whether to actually wrap the runnable.rethrow - Whether to rethrow the exception to store it in the returned future.protected <V> java.util.concurrent.Callable<V> wrapCallable(java.util.concurrent.Callable<V> command,
boolean loggingRequested,
boolean rethrow)
command - The command which to wrap.loggingRequested - Whether to actually wrap the callable.rethrow - Whether to rethrow the exception to provide it via the returned callable.