Evan Steinkerchner
Evan Steinkerchner

Reputation: 504

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.

Upvotes: 0

Views: 165

Answers (2)

a.drew.b
a.drew.b

Reputation: 84

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.

Upvotes: 1

eis
eis

Reputation: 53462

Try Quartz.

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

Upvotes: 0

Related Questions