Java Reference
In-Depth Information
mailSender.send(preparator);
}
}
In the prepare() method, you can prepare the MimeMessage object, which is precreated for
JavaMailSender . If there's any exception thrown, it will be converted into Spring's mail runtime
exception automatically.
6-5. Scheduling with Spring's JDK Timer Support
Problem
Your application has a basic scheduling requirement that you want to fulfill using JDK Timer. Moreover,
you want to configure your scheduling tasks in a declarative way.
Solution
Spring provides utility classes for JDK Timer to enable you to configure scheduling tasks in the bean
configuration file, without programming against the JDK Timer API.
How It Works
Creating a Timer Task
To use JDK Timer for scheduling, first create your task by extending the abstract class TimerTask . For
example, the following timer task executes the replicate() method of a file replicator:
package com.apress.springenterpriserecipes.replicator;
...
import java.util.TimerTask;
public class FileReplicationTask extends TimerTask {
private FileReplicator fileReplicator;
public void setFileReplicator(FileReplicator fileReplicator) {
this.fileReplicator = fileReplicator;
}
public void run() {
try {
fileReplicator.replicate();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
 
Search WWH ::




Custom Search