Java Reference
In-Depth Information
Position
Field Name
Range
4
Day of month
1-31
5
Month
1-12 or JAN-DEC
6
Day of week
1-7 or SUN-SAT
7
Year (optional)
1970-2099
Each part of a cron expression can be assigned a specific value (e.g., 3), a range (e.g., 1-5), a list (e.g.,
1,3,5), a wildcard ( * ; matches all values), or a question mark ( ? ; used in either of the “Day of month” and
“Day of week” fields for matching one of these fields but not both). For more information on the cron
expressions supported by CronTrigger , refer to its javadoc ( http://quartz.sourceforge.net/javado c/
org/quartz/CronTrigger.html ).
Using Quartz with Spring's Support
When using Quartz, you can create a job by implementing the Job interface and retrieve job data
from the job data map through JobExecutionContext . To decouple your job class from the Quartz
API, Spring provides QuartzJobBean , which you can extend to retrieve job data through setter methods.
QuartzJobBean converts the job data map into properties and injects them via the setter methods.
package com.apress.springenterpriserecipes.replicator;
...
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
public class FileReplicationJob extends QuartzJobBean {
private FileReplicator fileReplicator;
public void setFileReplicator(FileReplicator fileReplicator) {
this.fileReplicator = fileReplicator;
}
protected void executeInternal(JobExecutionContext context)
throws JobExecutionException {
try {
fileReplicator.replicate();
} catch (IOException e) {
throw new JobExecutionException(e);
}
}
}
Then you can configure a Quartz JobDetail object in Spring's bean configuration file through
JobDetailBean . By default, Spring uses this bean's name as the job name. You can modify it by setting
the name property.
Search WWH ::




Custom Search