java.util.concurrent.ExecutorService
(typically a java.util.concurrent.ThreadPoolExecutor or
java.util.concurrent.ScheduledThreadPoolExecutor ).
Defines common configuration settings and common lifecycle handling,
inheriting thread customization options (name, priority, etc) from
org..
java.util.concurrent.ExecutorService , java.util.concurrent.Executors , java.util.concurrent.ThreadPoolExecutor , java.util.concurrent.ScheduledThreadPoolExecutor
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private ApplicationContext | |
| private long | |
| private String | |
| private ExecutorService | |
| private volatile boolean | |
| private ExecutorLifecycleDelegate | |
| protected final Log | |
| private int | |
| private RejectedExecutionHandler | |
| private ThreadFactory | |
| private boolean | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | afterExecute(Runnable
the task that has been executed task, Throwable the exception thrown during execution, if any ex)An after-execute callback for framework subclasses to delegate to (for start/stop handling), and possibly also for custom subclasses to extend (making sure to call this implementation as well). |
| public void | afterPropertiesSet()
Implements org. Calls |
| private void | awaitTerminationIfNecessary(ExecutorService executor)
Wait for the executor to terminate, according to the value of the
|
| protected void | beforeExecute(Thread
the thread to run the task thread, Runnable the task to be executed task)A before-execute callback for framework subclasses to delegate to (for start/stop handling), and possibly also for custom subclasses to extend (making sure to call this implementation as well). |
| protected void | cancelRemainingTask(Runnable
the task to cancel (typically a task)RunnableFuture)Cancel the given remaining task which never commenced execution,
as returned from |
| public void | destroy()
Implements org. Calls |
| public int | getPhase()
Overrides default org. Return the lifecycle phase for pausing and resuming this executor. |
| public void | |
| protected abstract ExecutorService | Returns: a new ExecutorService instancethe ThreadFactory to use threadFactory, RejectedExecutionHandler the RejectedExecutionHandler to use rejectedExecutionHandler)Create the target |
| protected void | initiateEarlyShutdown()
Early shutdown signal: do not trigger further tasks, let existing tasks complete
before hitting the actual destruction step in the |
| public void | initiateShutdown()
Initiate a shutdown on the underlying ExecutorService, rejecting further task submissions. |
| public boolean | isRunning()
Implements org. Check whether this executor is not paused and has not been shut down either. |
| public void | onApplicationEvent(ContextClosedEvent
the event to respond to event)Implements org.
|
| public void | setAcceptTasksAfterContextClose(boolean acceptTasksAfterContextClose)
Set whether to accept further tasks after the application context close phase has begun. |
| public void | setApplicationContext(ApplicationContext
the ApplicationContext object to be used by this object applicationContext)Implements org. Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object. |
| public void | setAwaitTerminationMillis(long awaitTerminationMillis)
Variant of |
| public void | setAwaitTerminationSeconds(int awaitTerminationSeconds)
Set the maximum number of seconds that this executor is supposed to block on shutdown in order to wait for remaining tasks to complete their execution before the rest of the container continues to shut down. |
| public void | setBeanName(String
the name of the bean in the factory.
Note that this name is the actual bean name used in the factory, which may
differ from the originally specified name: in particular for inner bean
names, the actual bean name might have been made unique through appending
"#..." suffixes. Use the name)BeanFactoryUtils#originalBeanName(String)
method to extract the original bean name (without suffix), if desired.Implements org. Set the name of the bean in the bean factory that created this bean. |
| public void | |
| public void | setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler)
Set the RejectedExecutionHandler to use for the ExecutorService. |
| public void | setThreadFactory(ThreadFactory threadFactory)
Set the ThreadFactory to use for the ExecutorService's thread pool. |
| public void | setThreadNamePrefix(String threadNamePrefix)
Overrides org. Specify the prefix to use for the names of newly created threads. |
| public void | setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Set whether to wait for scheduled tasks to complete on shutdown, not interrupting running tasks and executing all tasks in the queue. |
| public void | shutdown()
Perform a full shutdown on the underlying ExecutorService, according to the corresponding configuration settings. |
| public void | start()
Implements org. Resume this executor if paused before (otherwise a no-op). |
| public void | stop()
Implements org. Pause this executor, not waiting for tasks to complete. |
| public void | stop(Runnable callback)
Overrides default org. Pause this executor, triggering the given callback once all currently executing tasks have completed. |
| acceptTasksAfterContextClose | back to summary |
|---|---|
| private boolean acceptTasksAfterContextClose | |
| applicationContext | back to summary |
|---|---|
| private ApplicationContext applicationContext
| |
| awaitTerminationMillis | back to summary |
|---|---|
| private long awaitTerminationMillis | |
| beanName | back to summary |
|---|---|
| private String beanName
| |
| executor | back to summary |
|---|---|
| private ExecutorService executor
| |
| lateShutdown | back to summary |
|---|---|
| private volatile boolean lateShutdown | |
| lifecycleDelegate | back to summary |
|---|---|
| private ExecutorLifecycleDelegate lifecycleDelegate
| |
| logger | back to summary |
|---|---|
| protected final Log logger | |
| phase | back to summary |
|---|---|
| private int phase | |
| rejectedExecutionHandler | back to summary |
|---|---|
| private RejectedExecutionHandler rejectedExecutionHandler | |
| threadFactory | back to summary |
|---|---|
| private ThreadFactory threadFactory | |
| threadNamePrefixSet | back to summary |
|---|---|
| private boolean threadNamePrefixSet | |
| waitForTasksToCompleteOnShutdown | back to summary |
|---|---|
| private boolean waitForTasksToCompleteOnShutdown | |
| ExecutorConfigurationSupport | back to summary |
|---|---|
| public ExecutorConfigurationSupport() | |
| afterExecute | back to summary |
|---|---|
| protected void afterExecute(Runnable task, Throwable ex) An after-execute callback for framework subclasses to delegate to (for start/stop handling), and possibly also for custom subclasses to extend (making sure to call this implementation as well).
| |
| afterPropertiesSet | back to summary |
|---|---|
| public void afterPropertiesSet() Implements org. Calls
| |
| awaitTerminationIfNecessary | back to summary |
|---|---|
| private void awaitTerminationIfNecessary(ExecutorService executor) Wait for the executor to terminate, according to the value of the
| |
| beforeExecute | back to summary |
|---|---|
| protected void beforeExecute(Thread thread, Runnable task) A before-execute callback for framework subclasses to delegate to (for start/stop handling), and possibly also for custom subclasses to extend (making sure to call this implementation as well).
| |
| cancelRemainingTask | back to summary |
|---|---|
| protected void cancelRemainingTask(Runnable task) Cancel the given remaining task which never commenced execution,
as returned from
| |
| destroy | back to summary |
|---|---|
| public void destroy() Implements org. Calls
| |
| getPhase | back to summary |
|---|---|
| public int getPhase() Overrides default org. Return the lifecycle phase for pausing and resuming this executor. | |
| initialize | back to summary |
|---|---|
| public void initialize() Set up the ExecutorService. | |
| initializeExecutor | back to summary |
|---|---|
| protected abstract ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) Create the target
| |
| initiateEarlyShutdown | back to summary |
|---|---|
| protected void initiateEarlyShutdown() Early shutdown signal: do not trigger further tasks, let existing tasks complete
before hitting the actual destruction step in the Called from The default implementation calls
| |
| initiateShutdown | back to summary |
|---|---|
| public void initiateShutdown() Initiate a shutdown on the underlying ExecutorService, rejecting further task submissions. The executor will not accept further tasks and will prevent further
scheduling of periodic tasks, letting existing tasks complete still.
This step is non-blocking and can be applied as an early shutdown signal
before following up with a full Automatically called for early shutdown signals on
| |
| isRunning | back to summary |
|---|---|
| public boolean isRunning() Implements org. Check whether this executor is not paused and has not been shut down either.
| |
| onApplicationEvent | back to summary |
|---|---|
| public void onApplicationEvent(ContextClosedEvent event) Implements org.
| |
| setAcceptTasksAfterContextClose | back to summary |
|---|---|
| public void setAcceptTasksAfterContextClose(boolean acceptTasksAfterContextClose) Set whether to accept further tasks after the application context close phase has begun. The default is
This flag will only have effect when the executor is running in a Spring
application context and able to receive the | |
| setApplicationContext | back to summary |
|---|---|
| public void setApplicationContext(ApplicationContext applicationContext) Implements org. Doc from org. Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object. Invoked after population of normal bean properties but before an init callback such
as
| |
| setAwaitTerminationMillis | back to summary |
|---|---|
| public void setAwaitTerminationMillis(long awaitTerminationMillis) Variant of
| |
| setAwaitTerminationSeconds | back to summary |
|---|---|
| public void setAwaitTerminationSeconds(int awaitTerminationSeconds) Set the maximum number of seconds that this executor is supposed to block on shutdown in order to wait for remaining tasks to complete their execution before the rest of the container continues to shut down. This is particularly useful if your remaining tasks are likely to need access to other resources that are also managed by the container. By default, this executor won't wait for the termination of tasks at all.
It will either shut down immediately, interrupting ongoing tasks and clearing
the remaining task queue - or, if the
In either case, if you specify an await-termination period using this property,
this executor will wait for the given time (max) for the termination of tasks.
As a rule of thumb, specify a significantly higher timeout here if you set
"waitForTasksToCompleteOnShutdown" to | |
| setBeanName | back to summary |
|---|---|
| public void setBeanName(String name) Implements org. Doc from org. Set the name of the bean in the bean factory that created this bean. Invoked after population of normal bean properties but before an
init callback such as
| |
| setPhase | back to summary |
|---|---|
| public void setPhase(int phase) Specify the lifecycle phase for pausing and resuming this executor.
The default is
| |
| setRejectedExecutionHandler | back to summary |
|---|---|
| public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler) Set the RejectedExecutionHandler to use for the ExecutorService. The default is the ExecutorService's default abort policy. | |
| setThreadFactory | back to summary |
|---|---|
| public void setThreadFactory(ThreadFactory threadFactory) Set the ThreadFactory to use for the ExecutorService's thread pool. The default is the underlying ExecutorService's default thread factory. In a Jakarta EE or other managed environment with JSR-236 support,
consider specifying a JNDI-located ManagedThreadFactory: by default,
to be found at "java:comp/DefaultManagedThreadFactory".
Use the "jee:jndi-lookup" namespace element in XML or the programmatic
| |
| setThreadNamePrefix | back to summary |
|---|---|
| public void setThreadNamePrefix(String threadNamePrefix) Overrides org. Doc from org. Specify the prefix to use for the names of newly created threads. Default is "SimpleAsyncTaskExecutor-".
| |
| setWaitForTasksToCompleteOnShutdown | back to summary |
|---|---|
| public void setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown) Set whether to wait for scheduled tasks to complete on shutdown, not interrupting running tasks and executing all tasks in the queue. The default is Note that Spring's container shutdown continues while ongoing tasks
are being completed. If you want this executor to block and wait for the
termination of tasks before the rest of the container continues to shut
down - e.g. in order to keep up other resources that your tasks may need -,
set the | |
| shutdown | back to summary |
|---|---|
| public void shutdown() Perform a full shutdown on the underlying ExecutorService, according to the corresponding configuration settings. This step potentially blocks for the configured termination period,
waiting for remaining tasks to complete. For an early shutdown signal
to not accept further tasks, call | |
| start | back to summary |
|---|---|
| public void start() Implements org. Resume this executor if paused before (otherwise a no-op).
| |
| stop | back to summary |
|---|---|
| public void stop() Implements org. Pause this executor, not waiting for tasks to complete.
| |
| stop | back to summary |
|---|---|
| public void stop(Runnable callback) Overrides default org. Pause this executor, triggering the given callback once all currently executing tasks have completed.
| |