img
. .
Group ID
Artifact ID
Version
Description
10.0.1
Contains useful helper classes.
com.google.guava
guava
1.6.1
The SLF4J logging library
org.slf4j
slf4j-log4j12
(www.slf4j.org) will be used as the
logging library for the samples in
this chapter. This library will help
chain the SLF4J logger to the
underlying log4j library for logging
purposes.
Task Scheduling in Spring
Enterprise applications often need to schedule tasks. In many applications, various tasks (such as
sending e-mail notifications to customers, running day-end jobs, doing data housekeeping, updating
data in batches, and so on) need to be scheduled to run on a regular basis, either in a fixed interval (e.g.,
every hour) or at a specific schedule (e.g., at 8 p.m. every night, from Monday to Friday). As mentioned,
task scheduling consists of three parts: the schedule definition (trigger), the task execution (scheduler),
and the task itself.
There are many different ways to trigger the execution of a task in a Spring application. One way is
to trigger a job externally from a scheduling system that already exists in the application deployment
environment. For example, many enterprises use commercial systems, such as Ctrl-M or CA Autosys, for
scheduling tasks. If the application is running on a Linux/Unix platform, the crontab scheduler can be
used. The job triggering can be done by sending a RESTful-WS request to the Spring application and
having Spring's MVC controller trigger the task.
Another way is to use the task scheduling support in Spring. Spring provides three options in terms
of task scheduling:
Support of JDK Timer: Spring supports JDK's Timer object for task scheduling.
·
Integrates with Quartz: The Quartz Scheduler (www.quartz-scheduler.org) is a
·
popular open source scheduling library.
Spring's own TaskScheduler abstraction: Spring 3 introduces the TaskScheduler
·
abstraction, which provides a simple way to schedule tasks and supports most
typical requirements.
In this section, we will focus on using Spring's TaskScheduler abstraction for task scheduling.
Introducing Spring TaskScheduler Abstraction
In Spring's TaskScheduler abstraction, there are mainly three participants:
The Trigger interface: The org.springframework.scheduling.Trigger interface
·
provides support for defining the triggering mechanism. Spring provides two
Trigger implementations. The CronTrigger class supports triggering based on a
cron expression, while the PeriodicTrigger class supports triggering based on an
initial delay and then a fixed interval.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home