Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to schedule (and reset) a task programmatically with SpringFramwork?

There is a situation where I want to invoke a method after some predetermined time, say 30 sec or 5 min.

Time needs to be configured at run time, means I should be able to change time dynamically from 5 min to 3 min.(reset the timer to new interval programmatically)

I am developing a dynamic web project using Spring framework.

I have checked the Quartz and Timer classes but they seem to read XML configuration for parameters such as delay, repeatInterval and so on.

How can I do that? Does Spring provide any support for this?

Thank you in advance.

like image 311
Sagar Avatar asked Jan 06 '11 06:01

Sagar


1 Answers

The easiest way is to configure and inject an instance of something that implements Spring's TaskScheduler interface (e.g. ThreadPoolTaskExecutor). This provides various methods to schedule tasks for delayed execution.

Quartz is overkill for this.

like image 178
skaffman Avatar answered Oct 11 '22 14:10

skaffman