简体   繁体   中英

Java Scheduled Task Across Multiple Executions

I've recently set up a Minecraft server for my friends and myself and I thought it would be a fun project to program my own maintenance wrapper for it, in which I periodically reboot, backup, and diagnose various aspects of the server.

I saw the ScheduledExecutorService class and figured it would be perfect, but I ran into a problem. I shut down my computer almost every night, and this class works on an elapsed time basis, and I would like to run some tasks only once a week. What would be the simplest way to implement this?

Is there another class I could use that automatically handles executing tasks based on actual time instead of elapsed time that I could use instead?

EDIT: I should add that I realize straightforward use of any standard class won't work. But it could easily be possible to save the next execution time to disk every time I execute a task and then recall the list when starting the wrapper back up the next time, allowing it to resume where it left off, more or less.

Using a scheduler library ( Quartz ) can perform these types of functions when coupled with a database back-end. Jobs can be scheduled to run at particular times or frequency.

Try Quartz .

Quartz contains persistence mechanism out of the box, among other things, like a scheduling service should.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM