Question

I'm searching for a solution to schedule a task at a given interval,
But I have to be able to restart the application and still have it execute the task at the right time. I don't really want to use any external libraries like Quartz. Any help is appreciated. :)

Was it helpful?

Solution

Just save the start time in a file. Then you can always use the modulo operator to get the next execution time:

nextExecutionTime = (startTime - currentTime) % interval + currentTime;

OTHER TIPS

You can use Linux crontab for a schedule a task.In your scenario you can export a jar and schedule it in crontab.Lets assume your jar is example.jar.

0 12 * * * java -jar /home/example.jar

This example.jar will fire at 12pm (noon) every day.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top