org.springframework.scheduling.concurrent
Class ExecutorConfigurationSupport

java.lang.Object
  extended by org.springframework.util.CustomizableThreadCreator
      extended by org.springframework.scheduling.concurrent.CustomizableThreadFactory
          extended by org.springframework.scheduling.concurrent.ExecutorConfigurationSupport
All Implemented Interfaces:
Serializable, ThreadFactory, Aware, BeanNameAware, DisposableBean, InitializingBean
Direct Known Subclasses:
ScheduledExecutorFactoryBean, ThreadPoolExecutorFactoryBean, ThreadPoolTaskExecutor, ThreadPoolTaskScheduler

public abstract class ExecutorConfigurationSupport
extends CustomizableThreadFactory
implements BeanNameAware, InitializingBean, DisposableBean

Base class for classes that are setting up a java.util.concurrent.ExecutorService (typically a ThreadPoolExecutor). Defines common configuration settings and common lifecycle handling.

Since:
3.0
Author:
Juergen Hoeller
See Also:
ExecutorService, Executors, ThreadPoolExecutor, Serialized Form

Field Summary
protected  Log logger
           
 
Constructor Summary
ExecutorConfigurationSupport()
           
 
Method Summary
 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  ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler)
          Create the target ExecutorService instance.
 void setBeanName(String name)
          Set the name of the bean in the bean factory that created this bean.
 void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler)
          Set the RejectedExecutionHandler to use for the ThreadPoolExecutor.
 void setThreadFactory(ThreadFactory threadFactory)
          Set the ThreadFactory to use for the ThreadPoolExecutor's thread pool.
 void setThreadNamePrefix(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.
 
Methods inherited from class org.springframework.scheduling.concurrent.CustomizableThreadFactory
newThread
 
Methods inherited from class org.springframework.util.CustomizableThreadCreator
createThread, getDefaultThreadNamePrefix, getThreadGroup, getThreadNamePrefix, getThreadPriority, isDaemon, nextThreadName, setDaemon, setThreadGroup, setThreadGroupName, setThreadPriority
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Constructor Detail

ExecutorConfigurationSupport

public ExecutorConfigurationSupport()
Method Detail

setThreadFactory

public void setThreadFactory(ThreadFactory threadFactory)
Set the ThreadFactory to use for the ThreadPoolExecutor's thread pool. Default is the ThreadPoolExecutor's default thread factory.

See Also:
Executors.defaultThreadFactory()

setThreadNamePrefix

public void setThreadNamePrefix(String threadNamePrefix)
Description copied from class: CustomizableThreadCreator
Specify the prefix to use for the names of newly created threads. Default is "SimpleAsyncTaskExecutor-".

Overrides:
setThreadNamePrefix in class CustomizableThreadCreator

setRejectedExecutionHandler

public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler)
Set the RejectedExecutionHandler to use for the ThreadPoolExecutor. Default is the ThreadPoolExecutor's default abort policy.

See Also:
ThreadPoolExecutor.AbortPolicy

setWaitForTasksToCompleteOnShutdown

public void setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Set whether to wait for scheduled tasks to complete on shutdown.

Default is "false". Switch this to "true" if you prefer fully completed tasks at the expense of a longer shutdown phase.

See Also:
ExecutorService.shutdown(), ExecutorService.shutdownNow()

setBeanName

public void setBeanName(String name)
Description copied from interface: BeanNameAware
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 InitializingBean.afterPropertiesSet() or a custom init-method.

Specified by:
setBeanName in interface BeanNameAware
Parameters:
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.

afterPropertiesSet

public void afterPropertiesSet()
Calls initialize() after the container applied all property values.

Specified by:
afterPropertiesSet in interface InitializingBean
See Also:
initialize()

initialize

public void initialize()
Set up the ExecutorService.


initializeExecutor

protected abstract ExecutorService initializeExecutor(ThreadFactory threadFactory,
                                                      RejectedExecutionHandler rejectedExecutionHandler)
Create the target ExecutorService instance. Called by afterPropertiesSet.

Parameters:
threadFactory - the ThreadFactory to use
rejectedExecutionHandler - the RejectedExecutionHandler to use
Returns:
a new ExecutorService instance
See Also:
afterPropertiesSet()

destroy

public void destroy()
Calls shutdown when the BeanFactory destroys the task executor instance.

Specified by:
destroy in interface DisposableBean
See Also:
shutdown()

shutdown

public void shutdown()
Perform a shutdown on the ThreadPoolExecutor.

See Also:
ExecutorService.shutdown()