سؤال

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