public class SimpleThreadPoolTaskExecutor extends SimpleThreadPool implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, InitializingBean, DisposableBean
TaskExecutor
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).
SimpleThreadPool
,
TaskExecutor
,
SchedulerFactoryBean.setTaskExecutor(java.util.concurrent.Executor)
TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE
Constructor and Description |
---|
SimpleThreadPoolTaskExecutor() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
|
void |
destroy()
Invoked by a BeanFactory on destruction of a singleton.
|
void |
execute(java.lang.Runnable task)
Execute the given
task . |
void |
execute(java.lang.Runnable task,
long startTimeout)
Execute the given
task . |
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.
|
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task)
Submit a Callable task for execution, receiving a Future representing that task.
|
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task)
Submit a Runnable task for execution, receiving a Future representing that task.
|
<T> ListenableFuture<T> |
submitListenable(java.util.concurrent.Callable<T> task)
Submit a
Callable task for execution, receiving a ListenableFuture
representing that task. |
ListenableFuture<?> |
submitListenable(java.lang.Runnable task)
Submit a
Runnable task for execution, receiving a ListenableFuture
representing that task. |
blockForAvailableThreads, clearFromBusyWorkersList, createWorkerThreads, getLog, getPoolSize, getThreadCount, getThreadNamePrefix, getThreadPriority, initialize, isMakeThreadsDaemons, isThreadsInheritContextClassLoaderOfInitializingThread, isThreadsInheritGroupOfInitializingThread, makeAvailable, runInThread, setInstanceId, setInstanceName, setMakeThreadsDaemons, setThreadCount, setThreadNamePrefix, setThreadPriority, setThreadsInheritContextClassLoaderOfInitializingThread, setThreadsInheritGroupOfInitializingThread, shutdown, shutdown
public void setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
SimpleThreadPool.shutdown(boolean)
public void afterPropertiesSet() throws SchedulerConfigException
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
SchedulerConfigException
public void execute(java.lang.Runnable task)
TaskExecutor
task
.
The call might return immediately if the implementation uses an asynchronous execution strategy, or might block in the case of synchronous execution.
execute
in interface java.util.concurrent.Executor
execute
in interface TaskExecutor
task
- the Runnable
to execute (never null
)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 ListenableFuture<?> submitListenable(java.lang.Runnable task)
AsyncListenableTaskExecutor
Runnable
task for execution, receiving a ListenableFuture
representing that task. The Future will return a null
result upon completion.submitListenable
in interface AsyncListenableTaskExecutor
task
- the Runnable
to execute (never null
)ListenableFuture
representing pending completion of the taskpublic <T> ListenableFuture<T> submitListenable(java.util.concurrent.Callable<T> task)
AsyncListenableTaskExecutor
Callable
task for execution, receiving a ListenableFuture
representing that task. The Future will return the Callable's result upon
completion.submitListenable
in interface AsyncListenableTaskExecutor
task
- the Callable
to execute (never null
)ListenableFuture
representing pending completion of the taskpublic boolean prefersShortLivedTasks()
prefersShortLivedTasks
in interface SchedulingTaskExecutor
true
if this TaskExecutor
prefers
short-lived taskspublic void destroy()
DisposableBean
destroy
in interface DisposableBean