public abstract class ExecutorConfigurationSupport extends org.frameworkset.schedule.CustomizableThreadFactory implements BeanNameAware, InitializingBean, DisposableBean
| 限定符和类型 | 字段和说明 |
|---|---|
protected org.slf4j.Logger |
logger |
| 构造器和说明 |
|---|
ExecutorConfigurationSupport() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
afterPropertiesSet()
Calls
initialize() after the container applied all property
values. |
void |
destroy()
Calls
shutdown when the BeanFactory destroys the task executor
instance. |
void |
initialize()
Set up the ExecutorService.
|
protected abstract java.util.concurrent.ExecutorService |
initializeExecutor(java.util.concurrent.ThreadFactory threadFactory,
java.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)
Create the target
ExecutorService instance. |
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.
|
void |
setBeanName(java.lang.String name)
Set the name of the bean in the bean factory that created this bean.
|
void |
setRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)
Set the RejectedExecutionHandler to use for the ExecutorService.
|
void |
setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
Set the ThreadFactory to use for the ExecutorService's thread pool.
|
void |
setThreadNamePrefix(java.lang.String threadNamePrefix) |
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.
|
void |
shutdown()
Perform a shutdown on the underlying ExecutorService.
|
public void setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
In a Java EE 7 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
org.frameworkset.jndi.JndiLocatorDelegate for convenient
lookup. Alternatively, consider using Spring's
DefaultManagedAwareThreadFactory with its fallback to local
threads in case of no managed thread factory found.
Executors.defaultThreadFactory(),
javax.enterprise.concurrent.ManagedThreadFactory,
DefaultManagedAwareThreadFactorypublic void setThreadNamePrefix(java.lang.String threadNamePrefix)
setThreadNamePrefix 在类中 org.frameworkset.util.CustomizableThreadCreatorpublic void setRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)
ThreadPoolExecutor.AbortPolicypublic void setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Default is "false", shutting down immediately through interrupting ongoing tasks and clearing the queue. Switch this flag to "true" if you prefer fully completed tasks at the expense of a longer shutdown phase.
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 "awaitTerminationSeconds"
property instead of or in addition to this property.
ExecutorService.shutdown(),
ExecutorService.shutdownNow()public void setAwaitTerminationSeconds(int awaitTerminationSeconds)
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
"waitForTasksToCompleteOnShutdown" flag has been set to true, it
will continue to fully execute all ongoing tasks as well as all remaining
tasks in the queue, in parallel to the rest of the container shutting
down.
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
true at the same time, since all remaining tasks in the queue
will still get executed - in contrast to the default shutdown behavior
where it's just about waiting for currently executing tasks that aren't
reacting to thread interruption.
ExecutorService.shutdown(),
ExecutorService.awaitTermination(long, java.util.concurrent.TimeUnit)public void setBeanName(java.lang.String name)
BeanNameAwareInvoked after population of normal bean properties but before an
init callback such as InitializingBean.afterPropertiesSet()
or a custom init-method.
setBeanName 在接口中 BeanNameAwarename - 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 BeanFactoryUtils#originalBeanName(String)
method to extract the original bean name (without suffix), if desired.public void afterPropertiesSet()
initialize() after the container applied all property
values.afterPropertiesSet 在接口中 InitializingBeaninitialize()public void initialize()
protected abstract java.util.concurrent.ExecutorService initializeExecutor(java.util.concurrent.ThreadFactory threadFactory,
java.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)
ExecutorService instance.
Called by afterPropertiesSet.threadFactory - the ThreadFactory to userejectedExecutionHandler - the RejectedExecutionHandler to useafterPropertiesSet()public void destroy()
shutdown when the BeanFactory destroys the task executor
instance.destroy 在接口中 DisposableBeanshutdown()public void shutdown()
ExecutorService.shutdown(),
ExecutorService.shutdownNow(),
awaitTerminationIfNecessary()