@Deprecated public class ThreadPoolTaskExecutor extends CustomizableThreadFactory implements SchedulingTaskExecutor, BeanNameAware, InitializingBean, DisposableBean
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor
in bean
style (through its "corePoolSize", "maxPoolSize", "keepAliveSeconds", "queueCapacity"
properties), exposing it as a Spring 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 TaskExecutor
,
simply wrap it with a ConcurrentTaskExecutor
adapter.
NOTE: This class implements Spring's
TaskExecutor
interface (and hence implicitly
the standard Java 5 Executor
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 backport Executor contract, in
particular regarding the TaskRejectedException
.
TaskExecutor
,
edu.emory.mathcs.backport.java.util.concurrent.Executor
,
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor
,
edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor
,
edu.emory.mathcs.backport.java.util.concurrent.Executors
,
ConcurrentTaskExecutor
,
Serialized FormModifier and Type | Field and Description |
---|---|
private boolean |
allowCoreThreadTimeOut
Deprecated.
|
private java.lang.String |
beanName
Deprecated.
|
private int |
corePoolSize
Deprecated.
|
private int |
keepAliveSeconds
Deprecated.
|
protected Log |
logger
Deprecated.
|
private int |
maxPoolSize
Deprecated.
|
private java.lang.Object |
poolSizeMonitor
Deprecated.
|
private int |
queueCapacity
Deprecated.
|
private RejectedExecutionHandler |
rejectedExecutionHandler
Deprecated.
|
private ThreadFactory |
threadFactory
Deprecated.
|
private boolean |
threadNamePrefixSet
Deprecated.
|
private ThreadPoolExecutor |
threadPoolExecutor
Deprecated.
|
private boolean |
waitForTasksToCompleteOnShutdown
Deprecated.
|
TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE
Constructor and Description |
---|
ThreadPoolTaskExecutor()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Deprecated.
Calls
initialize() after the container applied all property values. |
protected BlockingQueue |
createQueue(int queueCapacity)
Deprecated.
Create the BlockingQueue to use for the ThreadPoolExecutor.
|
void |
destroy()
Deprecated.
Calls
shutdown when the BeanFactory destroys
the task executor instance. |
void |
execute(java.lang.Runnable task)
Deprecated.
Implementation of both the JSR-166 backport Executor interface and the Spring
TaskExecutor interface, delegating to the ThreadPoolExecutor instance.
|
void |
execute(java.lang.Runnable task,
long startTimeout)
Deprecated.
Execute the given
task . |
int |
getActiveCount()
Deprecated.
Return the number of currently active threads.
|
int |
getCorePoolSize()
Deprecated.
Return the ThreadPoolExecutor's core pool size.
|
int |
getKeepAliveSeconds()
Deprecated.
Return the ThreadPoolExecutor's keep-alive seconds.
|
int |
getMaxPoolSize()
Deprecated.
Return the ThreadPoolExecutor's maximum pool size.
|
int |
getPoolSize()
Deprecated.
Return the current pool size.
|
ThreadPoolExecutor |
getThreadPoolExecutor()
Deprecated.
Return the underlying ThreadPoolExecutor for native access.
|
void |
initialize()
Deprecated.
Creates the BlockingQueue and the ThreadPoolExecutor.
|
boolean |
prefersShortLivedTasks()
Deprecated.
This task executor prefers short-lived work units.
|
void |
setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
Deprecated.
Specify whether to allow core threads to time out.
|
void |
setBeanName(java.lang.String name)
Deprecated.
Set the name of the bean in the bean factory that created this bean.
|
void |
setCorePoolSize(int corePoolSize)
Deprecated.
Set the ThreadPoolExecutor's core pool size.
|
void |
setKeepAliveSeconds(int keepAliveSeconds)
Deprecated.
Set the ThreadPoolExecutor's keep-alive seconds.
|
void |
setMaxPoolSize(int maxPoolSize)
Deprecated.
Set the ThreadPoolExecutor's maximum pool size.
|
void |
setQueueCapacity(int queueCapacity)
Deprecated.
Set the capacity for the ThreadPoolExecutor's BlockingQueue.
|
void |
setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler)
Deprecated.
Set the RejectedExecutionHandler to use for the ThreadPoolExecutor.
|
void |
setThreadFactory(ThreadFactory threadFactory)
Deprecated.
Set the ThreadFactory to use for the ThreadPoolExecutor's thread pool.
|
void |
setThreadNamePrefix(java.lang.String threadNamePrefix)
Deprecated.
Specify the prefix to use for the names of newly created threads.
|
void |
setWaitForTasksToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Deprecated.
Set whether to wait for scheduled tasks to complete on shutdown.
|
void |
shutdown()
Deprecated.
Perform a shutdown on the ThreadPoolExecutor.
|
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task)
Deprecated.
Submit a Callable task for execution, receiving a Future representing that task.
|
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task)
Deprecated.
Submit a Runnable task for execution, receiving a Future representing that task.
|
newThread
createThread, getDefaultThreadNamePrefix, getThreadGroup, getThreadNamePrefix, getThreadPriority, isDaemon, nextThreadName, setDaemon, setThreadGroup, setThreadGroupName, setThreadPriority
protected final Log logger
private final java.lang.Object poolSizeMonitor
private int corePoolSize
private int maxPoolSize
private int keepAliveSeconds
private boolean allowCoreThreadTimeOut
private int queueCapacity
private ThreadFactory threadFactory
private RejectedExecutionHandler rejectedExecutionHandler
private boolean waitForTasksToCompleteOnShutdown
private boolean threadNamePrefixSet
private java.lang.String beanName
private ThreadPoolExecutor threadPoolExecutor
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 backport-concurrent 3.0 or above (based on the code in Java 6).
edu.emory.mathcs.backport.java.util.concurrent.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.
edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue
,
edu.emory.mathcs.backport.java.util.concurrent.SynchronousQueue
public void setThreadFactory(ThreadFactory threadFactory)
Default is this executor itself (i.e. the factory that this executor
inherits from). See CustomizableThreadCreator
's
javadoc for available bean properties.
public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler)
edu.emory.mathcs.backport.java.util.concurrent.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.
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor#shutdown()
,
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor#shutdownNow()
public void setThreadNamePrefix(java.lang.String threadNamePrefix)
CustomizableThreadCreator
setThreadNamePrefix
in class CustomizableThreadCreator
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()
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 capacityedu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue
,
edu.emory.mathcs.backport.java.util.concurrent.SynchronousQueue
public ThreadPoolExecutor getThreadPoolExecutor() throws java.lang.IllegalStateException
null
)java.lang.IllegalStateException
- if the ThreadPoolTaskExecutor hasn't been initialized yetpublic void execute(java.lang.Runnable task)
execute
in interface java.util.concurrent.Executor
execute
in interface TaskExecutor
task
- the Runnable
to execute (never null
)edu.emory.mathcs.backport.java.util.concurrent.Executor#execute(Runnable)
,
TaskExecutor.execute(Runnable)
public void execute(java.lang.Runnable task, long startTimeout)
AsyncTaskExecutor
task
.execute
in interface AsyncTaskExecutor
task
- the Runnable
to execute (never null
)startTimeout
- the time duration (milliseconds) within which the task is
supposed to start. This is intended as a hint to the executor, allowing for
preferred handling of immediate tasks. Typical values are AsyncTaskExecutor.TIMEOUT_IMMEDIATE
or AsyncTaskExecutor.TIMEOUT_INDEFINITE
(the default as used by TaskExecutor.execute(Runnable)
).public java.util.concurrent.Future<?> submit(java.lang.Runnable task)
AsyncTaskExecutor
null
result upon completion.submit
in interface AsyncTaskExecutor
task
- the Runnable
to execute (never null
)public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
AsyncTaskExecutor
submit
in interface AsyncTaskExecutor
task
- the Callable
to execute (never null
)public boolean prefersShortLivedTasks()
prefersShortLivedTasks
in interface SchedulingTaskExecutor
true
if this TaskExecutor
prefers
short-lived taskspublic int getPoolSize()
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor#getPoolSize()
public int getActiveCount()
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor#getActiveCount()
public void destroy()
shutdown
when the BeanFactory destroys
the task executor instance.destroy
in interface DisposableBean
shutdown()
public void shutdown()
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor#shutdown()