문제

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. :)

도움이 되었습니까?

해결책

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;

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top