Save This Page
Home » spring-framework-2.5.5-with-dependencies » org.springframework » scheduling » backportconcurrent » [javadoc | source]
org.springframework.scheduling.backportconcurrent
public class: ThreadPoolTaskExecutor [javadoc | source]
java.lang.Object
   org.springframework.util.CustomizableThreadCreator
      org.springframework.scheduling.backportconcurrent.CustomizableThreadFactory
         org.springframework.scheduling.backportconcurrent.ThreadPoolTaskExecutor

All Implemented Interfaces:
    DisposableBean, BeanNameAware, SchedulingTaskExecutor, edu.emory.mathcs.backport.java.util.concurrent.Executor, InitializingBean, edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory

JavaBean that allows for configuring a JSR-166 backport edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor in bean style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity" properties), exposing it as a Spring org.springframework.core.task.TaskExecutor . This is an alternative to configuring a ThreadPoolExecutor instance directly using constructor injection, with a separate ConcurrentTaskExecutor adapter wrapping it.

For any custom needs, in particular for defining a edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor , it is recommended to use a straight definition of the Executor instance or a factory method definition that points to the JSR-166 backport edu.emory.mathcs.backport.java.util.concurrent.Executors class. To expose such a raw Executor as a Spring org.springframework.core.task.TaskExecutor , simply wrap it with a ConcurrentTaskExecutor adapter.

NOTE: This class implements Spring's org.springframework.core.task.TaskExecutor interface as well as the JSR-166 edu.emory.mathcs.backport.java.util.concurrent.Executor interface, with the former being the primary interface, the other just serving as secondary convenience. For this reason, the exception handling follows the TaskExecutor contract rather than the Executor contract, in particular regarding the org.springframework.core.task.TaskRejectedException .

Field Summary
protected final  Log logger     
Method from org.springframework.scheduling.backportconcurrent.ThreadPoolTaskExecutor Summary:
afterPropertiesSet,   createQueue,   destroy,   execute,   getActiveCount,   getCorePoolSize,   getKeepAliveSeconds,   getMaxPoolSize,   getPoolSize,   getThreadPoolExecutor,   initialize,   prefersShortLivedTasks,   setAllowCoreThreadTimeOut,   setBeanName,   setCorePoolSize,   setKeepAliveSeconds,   setMaxPoolSize,   setQueueCapacity,   setRejectedExecutionHandler,   setThreadFactory,   setThreadNamePrefix,   setWaitForTasksToCompleteOnShutdown,   shutdown
Methods from org.springframework.scheduling.backportconcurrent.CustomizableThreadFactory:
newThread
Methods from org.springframework.util.CustomizableThreadCreator:
createThread,   getDefaultThreadNamePrefix,   getThreadGroup,   getThreadNamePrefix,   getThreadPriority,   isDaemon,   nextThreadName,   setDaemon,   setThreadGroup,   setThreadGroupName,   setThreadNamePrefix,   setThreadPriority
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.scheduling.backportconcurrent.ThreadPoolTaskExecutor Detail:
 public  void afterPropertiesSet() 
    Calls initialize() after the container applied all property values.
 protected BlockingQueue createQueue(int queueCapacity) 
    Create the BlockingQueue to use for the ThreadPoolExecutor.

    A LinkedBlockingQueue instance will be created for a positive capacity value; a SynchronousQueue else.

 public  void destroy() 
    Calls shutdown when the BeanFactory destroys the task executor instance.
 public  void execute(Runnable task) 
    Implementation of both the JSR-166 backport Executor interface and the Spring TaskExecutor interface, delegating to the ThreadPoolExecutor instance.
 public int getActiveCount() 
    Return the number of currently active threads.
 public int getCorePoolSize() 
    Return the ThreadPoolExecutor's core pool size.
 public int getKeepAliveSeconds() 
    Return the ThreadPoolExecutor's keep-alive seconds.
 public int getMaxPoolSize() 
    Return the ThreadPoolExecutor's maximum pool size.
 public int getPoolSize() 
    Return the current pool size.
 public ThreadPoolExecutor getThreadPoolExecutor() throws IllegalStateException 
    Return the underlying ThreadPoolExecutor for native access.
 public  void initialize() 
    Creates the BlockingQueue and the ThreadPoolExecutor.
 public boolean prefersShortLivedTasks() 
    This task executor prefers short-lived work units.
 public  void setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) 
    Specify whether to allow core threads to time out. This enables dynamic growing and shrinking even in combination with a non-zero queue (since the max pool size will only grow once the queue is full).

    Default is "false". Note that this feature is only available on backport-concurrent 3.0 or above (based on the code in Java 6).

 public  void setBeanName(String name) 
 public  void setCorePoolSize(int corePoolSize) 
    Set the ThreadPoolExecutor's core pool size. Default is 1.

    This setting can be modified at runtime, for example through JMX.

 public  void setKeepAliveSeconds(int keepAliveSeconds) 
    Set the ThreadPoolExecutor's keep-alive seconds. Default is 60.

    This setting can be modified at runtime, for example through JMX.

 public  void setMaxPoolSize(int maxPoolSize) 
    Set the ThreadPoolExecutor's maximum pool size. Default is Integer.MAX_VALUE.

    This setting can be modified at runtime, for example through JMX.

 public  void setQueueCapacity(int queueCapacity) 
    Set the capacity for the ThreadPoolExecutor's BlockingQueue. Default is Integer.MAX_VALUE.

    Any positive value will lead to a LinkedBlockingQueue instance; any other value will lead to a SynchronousQueue instance.

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

    Default is this executor itself (i.e. the factory that this executor inherits from). See org.springframework.util.CustomizableThreadCreator 's javadoc for available bean properties.

 public  void setThreadNamePrefix(String threadNamePrefix) 
 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.

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