img
. . .
Topic 15
■■■
Task Scheduling in Spring
Task scheduling is a common feature in enterprise applications. Task scheduling mainly is composed of
three parts: the task (which is the piece of business logic needed to run at a specific time or on a regular
basis), the trigger (which specifies the condition under which the task should be executed), and the
scheduler (which executes the task based on the information from the trigger).
Specifically, this chapter will cover the following topics:
Task scheduling in Spring: We will discuss how Spring supports task scheduling,
·
focusing on the TaskScheduler abstraction introduced in Spring 3. We'll also cover
scheduling scenarios such as fixed-interval scheduling and cron expressions.
Asynchronous task execution: We will discuss how to use the new @Async
·
annotation in Spring 3 to execute tasks asynchronously.
Create a Project in STS for the Sample Projects
Let's create the sample project for this chapter. In STS, create a new Spring template project by choosing
Simple Spring JPA Utility Project. The reason of choosing this project template is that we will develop a
sample job that will update the data in the backend RDBMS.
Upon project creation, other dependencies are required, as shown in Table 15-1. Add them into
your project. Also, verify that the project is using Spring 3.1 and JDK 6.
Table 15-1. Maven Dependencies for Task Scheduling
Group ID
Artifact ID
Version
Description
1.0.1.RELEASE Spring Data JPA library.
org.springframework.data
spring-data-jpa
2.0
Joda-time (http://joda-
joda-time
joda-time
time.sourceforge.net/) is a date-
time API that Spring Data JPA
uses. In this chapter, we will use it
in our domain objects too.
1.3
Joda-time library for integration
joda-time
joda-time-hibernate
with Hibernate for date-time data
persistence.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home