I’m using Spring MVC+Spring Data with a Relational DB for a web application.
What I need to do is to trigger a check at midnight. In particular, I need to go through a list of persistent objects and check whether they expire on the just-started day.
Also, I would like to schedule some events at given intervals (e.g. once a week).
Does Spring offer a support for that?
EDIT: My solution
@Service
public class MyWork implements Runnable {
@Override
public void run() {
workToDo();
}
private void workToDo() { /*do it*/}
}
@Service
public class MySchedulerInvoker {
@Autowired
private TaskScheduler scheduler;
@Async
public void executeTask() {
scheduler.schedule(new MyWork(), new CronTrigger(
"* 15 9-17 * * MON-FRI"));
}
It does and its pretty easy to use – checkout Sprint Tasks Execution and Scheduling