0

I want to schedule a task to run only at a specific time of the day. Whats the easiest way to do this? I could probably use the Timer, TimerTask classes, but I was wondering if I could do the same with ExecutorService.

frodo
  • 1,561
  • 3
  • 21
  • 36
  • Sounds like you may want to use a script rather than Java or Scala. –  Jun 16 '17 at 22:23
  • Note that if this task is going to run from multiple machines, then any only in-memory tracking technique may lead to race condition. Avoiding that will require state tracking by your application using some tools like Quartz as Joe pointed out, or your own logic – Richeek Jun 17 '17 at 04:53
  • You can use `ScheduledExecutorService`. Check this question: https://stackoverflow.com/questions/20387881/how-to-run-certain-task-every-day-at-a-particular-time-using-scheduledexecutorse – berserkk Jun 17 '17 at 10:12

1 Answers1

1

You might be looking for Quartz. But it may also be on the heavy side if your needs are simple.

Joe Pallas
  • 2,105
  • 1
  • 14
  • 17