1

I have a particular requirement on scheduler. I need to run a scheduler after every 30 minutes. This can be done easily but the problem is this scheduler is depends on clock time. Like suppose I have start my program at 00:15 then with start my scheduler will not start. First scheduler will run at 00:30 and from then it will run with 30 minutes interval.

Need help on the same. I am using Java 8.

Souvik
  • 1,219
  • 3
  • 16
  • 38

3 Answers3

1

Timer and TimerTask classes can be used.

Timer class contains a method schedule() in that you can pass your task(TimerTask). Sigtnature of the method as follows : public void schedule(TimerTask task,long delay,long period) First parameter : TimerTask object Second paramter : delay in millisecond, after the mentioned milliseconds task will start to execute. Third parameter: period in millicond, subsequent executions will happen at regular intervals of mentioned period of time.

Refer to : https://docs.oracle.com/javase/8/docs/api/java/util/Timer.html

Avi Tyagi
  • 61
  • 3
  • Please read [How do I format my posts using Markdown or HTML?](http://stackoverflow.com/help/formatting). – buhtz Dec 18 '16 at 12:59
-1

What you looking for is called cron sceduling it can give you the ability to run your job for example every Monday at 10 am or every 30 minute of every hour here are some links

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html

How to create a Java cron job

https://www.mkyong.com/java/java-cron-job-to-run-a-jar-file/

Community
  • 1
  • 1
urag
  • 1,228
  • 9
  • 28
-1

This requirement is called crn job. The below cron settings needed to achieve the above requirement.

*/30 *  * * * 
Souvik
  • 1,219
  • 3
  • 16
  • 38