|
The Spring Framework | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
public class ThreadPoolTaskExecutor
JavaBean that allows for configuring a JDK 1.5 ThreadPoolExecutor in bean style (through "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity" properties), exposing it as both Spring TaskExecutor and JDK 1.5 Executor. This is an alternative to configuring a ThreadPoolExecutor instance directly using constructor injection, with a separate ConcurrentTaskExecutor adapter if necessary.
For any custom needs, in particular for defining a ScheduledThreadPoolExecutor, it is recommended to use a straight definition of the JDK 1.5 Executor implementation instance or a factory method definition that points to the JDK 1.5 Executors class. To expose it as a Spring TaskExecutor, wrap it with a ConcurrentTaskExecutor adapter.
TaskExecutor,
Executor,
ThreadPoolExecutor,
ScheduledThreadPoolExecutor,
Executors,
ConcurrentTaskExecutor| Field Summary | |
|---|---|
protected Log |
logger
|
| Constructor Summary | |
|---|---|
ThreadPoolTaskExecutor()
|
|
| Method Summary | |
|---|---|
void |
afterPropertiesSet()
Calls initialize() after the container applied all property values. |
protected BlockingQueue |
createQueue(int queueCapacity)
Create the BlockingQueue to use for the ThreadPoolExecutor. |
void |
destroy()
Calls shutdown when the BeanFactory destroys
the task executor instance. |
void |
execute(Runnable task)
Implementation of both the JDK 1.5 Executor interface and the Spring TaskExecutor interface, delegating to the ThreadPoolExecutor instance. |
void |
initialize()
Creates the BlockingQueue and the ThreadPoolExecutor. |
boolean |
prefersShortLivedTasks()
This task executor prefers short-lived work units. |
void |
setCorePoolSize(int corePoolSize)
Set the ThreadPoolExecutor's core pool size. |
void |
setKeepAliveSeconds(int keepAliveSeconds)
Set the ThreadPoolExecutor's keep alive seconds. |
void |
setMaxPoolSize(int maxPoolSize)
Set the ThreadPoolExecutor's maximum pool size. |
void |
setQueueCapacity(int queueCapacity)
Set the capacity for the ThreadPoolExecutor's BlockingQueue. |
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 |
shutdown()
Perform a shutdown on the ThreadPoolExecutor. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final Log logger
| Constructor Detail |
|---|
public ThreadPoolTaskExecutor()
| Method Detail |
|---|
public void setCorePoolSize(int corePoolSize)
public void setMaxPoolSize(int maxPoolSize)
Integer.MAX_VALUE.
public void setKeepAliveSeconds(int keepAliveSeconds)
public void setQueueCapacity(int queueCapacity)
Integer.MAX_VALUE.
Any positive value will lead to a LinkedBlockingQueue instance; any other value will lead to a SynchronousQueue instance.
LinkedBlockingQueue,
SynchronousQueuepublic void setThreadFactory(ThreadFactory threadFactory)
Executors.defaultThreadFactory()public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler)
ThreadPoolExecutor.AbortPolicypublic void afterPropertiesSet()
initialize() after the container applied all property values.
afterPropertiesSet in interface InitializingBeaninitialize()public void initialize()
createQueue(int)protected BlockingQueue createQueue(int queueCapacity)
A LinkedBlockingQueue instance will be created for a positive capacity value; a SynchronousQueue else.
queueCapacity - the specified queue capacity
LinkedBlockingQueue,
SynchronousQueuepublic void execute(Runnable task)
execute in interface Executorexecute in interface TaskExecutortask - the Runnable to executeExecutor.execute(Runnable),
TaskExecutor.execute(Runnable)public boolean prefersShortLivedTasks()
prefersShortLivedTasks in interface SchedulingTaskExecutorpublic void destroy()
shutdown when the BeanFactory destroys
the task executor instance.
destroy in interface DisposableBeanshutdown()public void shutdown()
ThreadPoolExecutor.shutdown()
|
The Spring Framework | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||