public abstract class ExecutorConfigurationSupport extends CustomizableThreadFactory implements BeanNameAware, InitializingBean, DisposableBean
java.util.concurrent.ExecutorService
(typically a ThreadPoolExecutor
).
Defines common configuration settings and common lifecycle handling.ExecutorService
,
Executors
,
ThreadPoolExecutor
,
Serialized FormModifier and Type | Field and Description |
---|---|
private java.lang.String |
beanName |
private java.util.concurrent.ExecutorService |
executor |
protected Log |
logger |
private java.util.concurrent.RejectedExecutionHandler |
rejectedExecutionHandler |
private java.util.concurrent.ThreadFactory |
threadFactory |
private boolean |
threadNamePrefixSet |
private boolean |
waitForTasksToCompleteOnShutdown |
Constructor and Description |
---|
ExecutorConfigurationSupport() |
Modifier and Type | Method and Description |
---|---|
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 |
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 ThreadPoolExecutor.
|
void |
setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
Set the ThreadFactory to use for the ThreadPoolExecutor's thread pool.
|
void |
setThreadNamePrefix(java.lang.String threadNamePrefix)
Specify the prefix to use for the names of newly created threads.
|
void |
setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Set whether to wait for scheduled tasks to complete on shutdown.
|
void |
shutdown()
Perform a shutdown on the ThreadPoolExecutor.
|
newThread
createThread, getDefaultThreadNamePrefix, getThreadGroup, getThreadNamePrefix, getThreadPriority, isDaemon, nextThreadName, setDaemon, setThreadGroup, setThreadGroupName, setThreadPriority
protected final Log logger
private java.util.concurrent.ThreadFactory threadFactory
private boolean threadNamePrefixSet
private java.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler
private boolean waitForTasksToCompleteOnShutdown
private java.lang.String beanName
private java.util.concurrent.ExecutorService executor
public void setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
Executors.defaultThreadFactory()
public void setThreadNamePrefix(java.lang.String threadNamePrefix)
CustomizableThreadCreator
setThreadNamePrefix
in class CustomizableThreadCreator
public void setRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)
ThreadPoolExecutor.AbortPolicy
public void setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Default is "false". Switch this to "true" if you prefer fully completed tasks at the expense of a longer shutdown phase.
ExecutorService.shutdown()
,
ExecutorService.shutdownNow()
public void setBeanName(java.lang.String name)
BeanNameAware
Invoked after population of normal bean properties but before an
init callback such as InitializingBean.afterPropertiesSet()
or a custom init-method.
setBeanName
in interface BeanNameAware
name
- 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
in interface InitializingBean
initialize()
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
in interface DisposableBean
shutdown()
public void shutdown()
ExecutorService.shutdown()