Class SRScheduledThreadPoolExecutor
- All Implemented Interfaces:
AutoCloseable,Executor,ExecutorService,ScheduledExecutorService
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy -
Constructor Summary
ConstructorsConstructorDescriptionSRScheduledThreadPoolExecutor(int corePoolSize) Creates a newScheduledThreadPoolExecutorwith the given core pool size.SRScheduledThreadPoolExecutor(int corePoolSize, RejectedExecutionHandler handler) Creates a new ScheduledThreadPoolExecutor with the given initial parameters.SRScheduledThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory) Creates a newScheduledThreadPoolExecutorwith the given initial parameters.SRScheduledThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler) Creates a new ScheduledThreadPoolExecutor with the given initial parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterExecute(Runnable r, Throwable t) Method invoked upon completion of execution of the given Runnable.Methods inherited from class java.util.concurrent.ScheduledThreadPoolExecutor
decorateTask, decorateTask, execute, getContinueExistingPeriodicTasksAfterShutdownPolicy, getExecuteExistingDelayedTasksAfterShutdownPolicy, getQueue, getRemoveOnCancelPolicy, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, setContinueExistingPeriodicTasksAfterShutdownPolicy, setExecuteExistingDelayedTasksAfterShutdownPolicy, setRemoveOnCancelPolicy, shutdown, shutdownNow, submit, submit, submitMethods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, 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, toStringMethods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskForMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, close, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated
-
Constructor Details
-
SRScheduledThreadPoolExecutor
public SRScheduledThreadPoolExecutor(int corePoolSize) Creates a newScheduledThreadPoolExecutorwith the given core pool size.- Parameters:
corePoolSize- the number of threads to keep in the pool, even if they are idle, unlessallowCoreThreadTimeOutis set- Throws:
IllegalArgumentException- ifcorePoolSize < 0
-
SRScheduledThreadPoolExecutor
Creates a new ScheduledThreadPoolExecutor with the given initial parameters.- Parameters:
corePoolSize- the number of threads to keep in the pool, even if they are idle, unlessallowCoreThreadTimeOutis sethandler- the handler to use when execution is blocked because the thread bounds and queue capacities are reached- Throws:
IllegalArgumentException- ifcorePoolSize < 0NullPointerException- ifhandleris null
-
SRScheduledThreadPoolExecutor
Creates a newScheduledThreadPoolExecutorwith the given initial parameters.- Parameters:
corePoolSize- the number of threads to keep in the pool, even if they are idle, unlessallowCoreThreadTimeOutis setthreadFactory- the factory to use when the executor creates a new thread- Throws:
IllegalArgumentException- ifcorePoolSize < 0NullPointerException- ifthreadFactoryis null
-
SRScheduledThreadPoolExecutor
public SRScheduledThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler) Creates a new ScheduledThreadPoolExecutor with the given initial parameters.- Parameters:
corePoolSize- the number of threads to keep in the pool, even if they are idle, unlessallowCoreThreadTimeOutis setthreadFactory- the factory to use when the executor creates a new threadhandler- the handler to use when execution is blocked because the thread bounds and queue capacities are reached- Throws:
IllegalArgumentException- ifcorePoolSize < 0NullPointerException- ifthreadFactoryorhandleris null
-
-
Method Details
-
afterExecute
Method invoked upon completion of execution of the given Runnable. This method is invoked by the thread that executed the task. If non-null, the Throwable is the uncaught
RuntimeExceptionorErrorthat caused execution to terminate abruptly.This implementation does nothing, but may be customized in subclasses. Note: To properly nest multiple overridings, subclasses should generally invoke
super.afterExecuteat the beginning of this method.Note: When actions are enclosed in tasks (such as
FutureTask) either explicitly or via methods such assubmit, these task objects catch and maintain computational exceptions, and so they do not cause abrupt termination, and the internal exceptions are not passed to this method. If you would like to trap both kinds of failures in this method, you can further probe for such cases, as in this sample subclass that prints either the direct cause or the underlying exception if a task has been aborted:class ExtendedExecutor extends ThreadPoolExecutor { // ... protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); if (t == null && r instanceof Future<?>) { try { Object result = ((Future<?>) r).get(); } catch (CancellationException ce) { t = ce; } catch (ExecutionException ee) { t = ee.getCause(); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); // ignore/reset } } if (t != null) System.out.println(t); } }- Overrides:
afterExecutein classThreadPoolExecutor- Parameters:
r- the runnable that has completedt- the exception that caused termination, or null if execution completed normally
-