0

I want to execute a Java program in Eclipse multiple times with a certain delay. I was trying to use ScheduleAtFixedRate() to re-execute the program after a certain interval of time. So what is the main difference between ScheduleAtFixedRate() and ScheduledExecutorService?

What is the advantage of using the latter? Does it continue running the schedule of execution when the computer is set on a sleep mode?

4

2 回答 2

2

Provided you mean .scheduleAtFixedRate() (note the little s), then it is a method provided by ScheduledExecutorService. As such, there is no {dis,}advantage to using either.

You can create a ScheduledExecutorService by calling, for instance:

final ScheduledExecutorService service
    = Executors.newScheduledThreadPool(...);
service.scheduleAtFixedRate(...);

As to:

Does it continue running the schedule of execution when the computer is set on a sleep mode?

No. It is the OS which puts the computer to sleep, and it is the OS which you should instruct to wake up at the time(s) you want. A running Java program is a JVM is a process is ultimately controlled by the OS.

于 2013-07-05T08:21:35.713 回答
0

ScheduledExecutorService is an interface that defines the behaviour of a task executor and ScheduleAtFixedRate() is method of this interface which expects the implementation class i.e the executor to execute the input task at fixed interval.

When your computer goes to sleep or hibernates nothing will execute.

于 2013-07-05T08:28:03.333 回答