Pregunta

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

¿Fue útil?

Solución

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;

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top