|
spring-context | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.springframework.util.CustomizableThreadCreator
org.springframework.scheduling.concurrent.CustomizableThreadFactory
org.springframework.scheduling.concurrent.ExecutorConfigurationSupport
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
public class ThreadPoolTaskExecutor
JavaBean that allows for configuring a JDK 1.5 ThreadPoolExecutor
in bean style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity"
properties) and exposing it as a Spring TaskExecutor.
This class is also well suited for management and monitoring (e.g. through JMX),
providing several useful attributes: "corePoolSize", "maxPoolSize", "keepAliveSeconds"
(all supporting updates at runtime); "poolSize", "activeCount" (for introspection only).
For an alternative, you may set up a ThreadPoolExecutor instance directly using
constructor injection, or use a factory method definition that points to the JDK 1.5
Executors class. To expose such a raw Executor as a
Spring TaskExecutor, simply wrap it with a
ConcurrentTaskExecutor adapter.
NOTE: This class implements Spring's
TaskExecutor interface as well as the JDK 1.5
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 TaskRejectedException.
If you prefer native ExecutorService exposure instead,
consider ThreadPoolExecutorFactoryBean as an alternative to this class.
TaskExecutor,
ThreadPoolExecutor,
ConcurrentTaskExecutor,
Serialized Form| Field Summary |
|---|
| Fields inherited from class org.springframework.scheduling.concurrent.ExecutorConfigurationSupport |
|---|
logger |
| Fields inherited from interface org.springframework.core.task.AsyncTaskExecutor |
|---|
TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE |
| Constructor Summary | |
|---|---|
ThreadPoolTaskExecutor()
|
|
| Method Summary | ||
|---|---|---|
protected java.util.concurrent.BlockingQueue<java.lang.Runnable> |
createQueue(int queueCapacity)
Create the BlockingQueue to use for the ThreadPoolExecutor. |
|
void |
execute(java.lang.Runnable task)
|
|
void |
execute(java.lang.Runnable task,
long startTimeout)
|
|
int |
getActiveCount()
Return the number of currently active threads. |
|
int |
getCorePoolSize()
Return the ThreadPoolExecutor's core pool size. |
|
int |
getKeepAliveSeconds()
Return the ThreadPoolExecutor's keep-alive seconds. |
|
int |
getMaxPoolSize()
Return the ThreadPoolExecutor's maximum pool size. |
|
int |
getPoolSize()
Return the current pool size. |
|
java.util.concurrent.ThreadPoolExecutor |
getThreadPoolExecutor()
Return the underlying ThreadPoolExecutor for native access. |
|
protected java.util.concurrent.ExecutorService |
initializeExecutor(java.util.concurrent.ThreadFactory threadFactory,
java.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)
Create the target ExecutorService instance. |
|
boolean |
prefersShortLivedTasks()
This task executor prefers short-lived work units. |
|
void |
setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
Specify whether to allow core threads to time out. |
|
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. |
|
|
submit(java.util.concurrent.Callable<T> task)
|
|
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task)
|
|
| Methods inherited from class org.springframework.scheduling.concurrent.ExecutorConfigurationSupport |
|---|
afterPropertiesSet, destroy, initialize, setBeanName, setRejectedExecutionHandler, setThreadFactory, setThreadNamePrefix, setWaitForTasksToCompleteOnShutdown, shutdown |
| 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 |
| Constructor Detail |
|---|
public ThreadPoolTaskExecutor()
| Method Detail |
|---|
public void setCorePoolSize(int corePoolSize)
This setting can be modified at runtime, for example through JMX.
public int getCorePoolSize()
public void setMaxPoolSize(int maxPoolSize)
Integer.MAX_VALUE.
This setting can be modified at runtime, for example through JMX.
public int getMaxPoolSize()
public void setKeepAliveSeconds(int keepAliveSeconds)
This setting can be modified at runtime, for example through JMX.
public int getKeepAliveSeconds()
public void setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
Default is "false". Note that this feature is only available on Java 6 or above. On Java 5, consider switching to the backport-concurrent version of ThreadPoolTaskExecutor which also supports this feature.
ThreadPoolExecutor.allowCoreThreadTimeOut(boolean)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,
SynchronousQueue
protected java.util.concurrent.ExecutorService initializeExecutor(java.util.concurrent.ThreadFactory threadFactory,
java.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)
ExecutorConfigurationSupportExecutorService instance.
Called by afterPropertiesSet.
initializeExecutor in class ExecutorConfigurationSupportthreadFactory - the ThreadFactory to userejectedExecutionHandler - the RejectedExecutionHandler to use
ExecutorConfigurationSupport.afterPropertiesSet()protected java.util.concurrent.BlockingQueue<java.lang.Runnable> createQueue(int queueCapacity)
A LinkedBlockingQueue instance will be created for a positive capacity value; a SynchronousQueue else.
queueCapacity - the specified queue capacity
LinkedBlockingQueue,
SynchronousQueue
public java.util.concurrent.ThreadPoolExecutor getThreadPoolExecutor()
throws java.lang.IllegalStateException
null)
java.lang.IllegalStateException - if the ThreadPoolTaskExecutor hasn't been initialized yetpublic int getPoolSize()
ThreadPoolExecutor.getPoolSize()public int getActiveCount()
ThreadPoolExecutor.getActiveCount()public void execute(java.lang.Runnable task)
execute in interface java.util.concurrent.Executorexecute in interface org.springframework.core.task.TaskExecutor
public void execute(java.lang.Runnable task,
long startTimeout)
execute in interface org.springframework.core.task.AsyncTaskExecutorpublic java.util.concurrent.Future<?> submit(java.lang.Runnable task)
submit in interface org.springframework.core.task.AsyncTaskExecutorpublic <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
submit in interface org.springframework.core.task.AsyncTaskExecutorpublic boolean prefersShortLivedTasks()
prefersShortLivedTasks in interface SchedulingTaskExecutortrue if this TaskExecutor prefers
short-lived tasks
|
spring-context | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||