Difference between scheduleAtFixedRate and schedule in the ScheduledExecutorService class

5

What is the difference between scheduleAtFixedRate and schedule ?

I'm developing an app on Android that I want to have a delay of 50 minutes before starting an action and repeat that same action in the next 50 minutes, but I'd like to know which one will satisfy my need, in this case .

    
asked by anonymous 12.02.2015 / 16:32

1 answer

2

The difference between this methods is as follows:

ScheduledExecutorService.schedule

When calling this method you should define a Runnable that is your task, the time the action is to be executed and TimeUnit (if and hoars, minutes, etc.). This method will perform what we call one-shot action . Your runnable will only run once in the defined time. (There are overloaded versions that accept Calleables instead of Runnables)

ScheduledExecutorService.scheduleAtAFixedRate

Already in the call of scheduleAtAFixedRate m [all Creates and executes an action - Runnable/Callable periodic that is activated for the first time after the given initial delay. If any execution of the task throws an exception, subsequent executions are suppressed, ie they are not executed. Otherwise, the task will only terminate via cancellation or shutidown of executor .

Take note of this detail:

If any execution of this task takes more time than its period, then subsequent executions can be started later, but there will be no concurrency execution.

Please take a look at JavaDocs

link

    
25.06.2015 / 22:30