Class SimpleThreadPoolTaskExecutor
- java.lang.Object
- org.quartz.simpl.SimpleThreadPool
- org.springframework.scheduling.quartz.SimpleThreadPoolTaskExecutor
- All Implemented Interfaces:
Executor
,ThreadPool
,DisposableBean
,InitializingBean
,AsyncListenableTaskExecutor
,AsyncTaskExecutor
,TaskExecutor
,SchedulingTaskExecutor
public class SimpleThreadPoolTaskExecutor extends SimpleThreadPool implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, InitializingBean, DisposableBean
Subclass of Quartz's SimpleThreadPool that implements Spring'sTaskExecutor
interface and listens to Spring lifecycle callbacks.Can be shared between a Quartz Scheduler (specified as "taskExecutor") and other TaskExecutor users, or even used completely independent of a Quartz Scheduler (as plain TaskExecutor backend).
- Since:
- 2.0
- Author:
- Juergen Hoeller
- See Also:
SimpleThreadPool
,TaskExecutor
,SchedulerFactoryBean.setTaskExecutor(java.util.concurrent.Executor)
Field Summary
Fields inherited from interface org.springframework.core.task.AsyncTaskExecutor
TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE
Constructor Summary
Constructors Constructor Description SimpleThreadPoolTaskExecutor()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.void
destroy()
Invoked by the containingBeanFactory
on destruction of a bean.void
execute(Runnable task)
Execute the giventask
.void
execute(Runnable task, long startTimeout)
Execute the giventask
.boolean
prefersShortLivedTasks()
This task executor prefers short-lived work units.void
setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Set whether to wait for running jobs to complete on shutdown.Future<?>
submit(Runnable task)
Submit a Runnable task for execution, receiving a Future representing that task.<T> Future<T>
submit(Callable<T> task)
Submit a Callable task for execution, receiving a Future representing that task.ListenableFuture<?>
submitListenable(Runnable task)
Submit aRunnable
task for execution, receiving aListenableFuture
representing that task.<T> ListenableFuture<T>
submitListenable(Callable<T> task)
Submit aCallable
task for execution, receiving aListenableFuture
representing that task.Methods inherited from class org.quartz.simpl.SimpleThreadPool
blockForAvailableThreads, clearFromBusyWorkersList, createWorkerThreads, getLog, getPoolSize, getThreadCount, getThreadNamePrefix, getThreadPriority, initialize, isMakeThreadsDaemons, isThreadsInheritContextClassLoaderOfInitializingThread, isThreadsInheritGroupOfInitializingThread, makeAvailable, runInThread, setInstanceId, setInstanceName, setMakeThreadsDaemons, setThreadCount, setThreadNamePrefix, setThreadPriority, setThreadsInheritContextClassLoaderOfInitializingThread, setThreadsInheritGroupOfInitializingThread, shutdown, shutdown
Constructor Detail
SimpleThreadPoolTaskExecutor
public SimpleThreadPoolTaskExecutor()
Method Detail
setWaitForJobsToCompleteOnShutdown
public void setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Set whether to wait for running jobs to complete on shutdown. Default is "false".- See Also:
SimpleThreadPool.shutdown(boolean)
afterPropertiesSet
public void afterPropertiesSet() throws SchedulerConfigException
Description copied from interface:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
- Throws:
SchedulerConfigException
execute
public void execute(Runnable task)
Description copied from interface:TaskExecutor
Execute the giventask
.The call might return immediately if the implementation uses an asynchronous execution strategy, or might block in the case of synchronous execution.
- Specified by:
execute
in interfaceExecutor
- Specified by:
execute
in interfaceTaskExecutor
- Parameters:
task
- theRunnable
to execute (nevernull
)
execute
public void execute(Runnable task, long startTimeout)
Description copied from interface:AsyncTaskExecutor
Execute the giventask
.- Specified by:
execute
in interfaceAsyncTaskExecutor
- Parameters:
task
- theRunnable
to execute (nevernull
)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 areAsyncTaskExecutor.TIMEOUT_IMMEDIATE
orAsyncTaskExecutor.TIMEOUT_INDEFINITE
(the default as used byTaskExecutor.execute(Runnable)
).
submit
public Future<?> submit(Runnable task)
Description copied from interface:AsyncTaskExecutor
Submit a Runnable task for execution, receiving a Future representing that task. The Future will return anull
result upon completion.- Specified by:
submit
in interfaceAsyncTaskExecutor
- Parameters:
task
- theRunnable
to execute (nevernull
)- Returns:
- a Future representing pending completion of the task
submit
public <T> Future<T> submit(Callable<T> task)
Description copied from interface:AsyncTaskExecutor
Submit a Callable task for execution, receiving a Future representing that task. The Future will return the Callable's result upon completion.- Specified by:
submit
in interfaceAsyncTaskExecutor
- Parameters:
task
- theCallable
to execute (nevernull
)- Returns:
- a Future representing pending completion of the task
submitListenable
public ListenableFuture<?> submitListenable(Runnable task)
Description copied from interface:AsyncListenableTaskExecutor
Submit aRunnable
task for execution, receiving aListenableFuture
representing that task. The Future will return anull
result upon completion.- Specified by:
submitListenable
in interfaceAsyncListenableTaskExecutor
- Parameters:
task
- theRunnable
to execute (nevernull
)- Returns:
- a
ListenableFuture
representing pending completion of the task
submitListenable
public <T> ListenableFuture<T> submitListenable(Callable<T> task)
Description copied from interface:AsyncListenableTaskExecutor
Submit aCallable
task for execution, receiving aListenableFuture
representing that task. The Future will return the Callable's result upon completion.- Specified by:
submitListenable
in interfaceAsyncListenableTaskExecutor
- Parameters:
task
- theCallable
to execute (nevernull
)- Returns:
- a
ListenableFuture
representing pending completion of the task
prefersShortLivedTasks
public boolean prefersShortLivedTasks()
This task executor prefers short-lived work units.- Specified by:
prefersShortLivedTasks
in interfaceSchedulingTaskExecutor
- Returns:
true
if thisTaskExecutor
prefers short-lived tasks
destroy
public void destroy()
Description copied from interface:DisposableBean
Invoked by the containingBeanFactory
on destruction of a bean.- Specified by:
destroy
in interfaceDisposableBean