public class

TimerTaskExecutor

extends Object
implements BeanNameAware DisposableBean InitializingBean SchedulingTaskExecutor
java.lang.Object
   ↳ org.springframework.scheduling.timer.TimerTaskExecutor

This class is deprecated.
as of Spring 3.0, in favor of the scheduling.concurrent package which is based on Java 5's java.util.concurrent.ExecutorService

Class Overview

TaskExecutor implementation that uses a single Timer for executing all tasks, effectively resulting in serialized asynchronous execution on a single thread.

See Also

Summary

[Expand]
Inherited Constants
From interface org.springframework.core.task.AsyncTaskExecutor
Fields
protected final Log logger
Public Constructors
TimerTaskExecutor()
Create a new TimerTaskExecutor that needs to be further configured and initialized.
TimerTaskExecutor(Timer timer)
Create a new TimerTaskExecutor for the given Timer.
Public Methods
void afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
void destroy()
Cancel the Timer on bean factory shutdown, stopping all scheduled tasks.
void execute(Runnable task, long startTimeout)
Execute the given task.
void execute(Runnable task)
Schedules the given Runnable on this executor's Timer instance, wrapping it in a DelegatingTimerTask.
boolean prefersShortLivedTasks()
This task executor prefers short-lived work units.
void setBeanName(String beanName)
Set the name of the bean in the bean factory that created this bean.
void setDelay(long delay)
Set the delay to use for scheduling tasks passed into the plain execute(Runnable) method.
void setTimer(Timer timer)
Set the Timer to use for this TimerTaskExecutor, for example a shared Timer instance defined by a TimerFactoryBean.
<T> Future<T> submit(Callable<T> task)
Submit a Callable task for execution, receiving a Future representing that task.
Future<?> submit(Runnable task)
Submit a Runnable task for execution, receiving a Future representing that task.
Protected Methods
Timer createTimer()
Create a new Timer instance.
final Timer getTimer()
Return the underlying Timer behind this TimerTaskExecutor.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.util.concurrent.Executor
From interface org.springframework.beans.factory.BeanNameAware
From interface org.springframework.beans.factory.DisposableBean
From interface org.springframework.beans.factory.InitializingBean
From interface org.springframework.core.task.AsyncTaskExecutor
From interface org.springframework.core.task.TaskExecutor
From interface org.springframework.scheduling.SchedulingTaskExecutor

Fields

protected final Log logger

Public Constructors

public TimerTaskExecutor ()

Create a new TimerTaskExecutor that needs to be further configured and initialized.

public TimerTaskExecutor (Timer timer)

Create a new TimerTaskExecutor for the given Timer.

Parameters
timer the Timer to wrap

Public Methods

public void afterPropertiesSet ()

Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

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.

public void destroy ()

Cancel the Timer on bean factory shutdown, stopping all scheduled tasks.

See Also

public void execute (Runnable task, long startTimeout)

Execute the given task.

Parameters
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 TIMEOUT_IMMEDIATE or TIMEOUT_INDEFINITE (the default as used by execute(Runnable)).

public void execute (Runnable task)

Schedules the given Runnable on this executor's Timer instance, wrapping it in a DelegatingTimerTask.

Parameters
task the task to be executed

public boolean prefersShortLivedTasks ()

This task executor prefers short-lived work units.

Returns
  • true if this TaskExecutor prefers short-lived tasks

public void setBeanName (String beanName)

Set the name of the bean in the bean factory that created this bean.

Invoked after population of normal bean properties but before an init callback such as afterPropertiesSet() or a custom init-method.

Parameters
beanName 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 setDelay (long delay)

Set the delay to use for scheduling tasks passed into the plain execute(Runnable) method. Default is 0.

Note that calls to execute(Runnable, long) will use the given timeout as delay if it is lower than the general delay.

Parameters
delay the delay in milliseconds before the task is to be executed

public void setTimer (Timer timer)

Set the Timer to use for this TimerTaskExecutor, for example a shared Timer instance defined by a TimerFactoryBean.

If not specified, a default internal Timer instance will be used.

Parameters
timer the Timer to use for this TimerTaskExecutor
See Also

public Future<T> submit (Callable<T> task)

Submit a Callable task for execution, receiving a Future representing that task. The Future will return the Callable's result upon completion.

Parameters
task the Callable to execute (never null)
Returns
  • a Future representing pending completion of the task

public Future<?> submit (Runnable task)

Submit a Runnable task for execution, receiving a Future representing that task. The Future will return a null result upon completion.

Parameters
task the Runnable to execute (never null)
Returns
  • a Future representing pending completion of the task

Protected Methods

protected Timer createTimer ()

Create a new Timer instance. Called by afterPropertiesSet if no Timer has been specified explicitly.

The default implementation creates a plain non-daemon Timer. If overridden, subclasses must take care to ensure that a non-null Timer is returned from the execution of this method.

protected final Timer getTimer ()

Return the underlying Timer behind this TimerTaskExecutor.