Difference between scheduleAtFixedRate and Schedule in the Scheduledexecutorservice class

Asked

Viewed 732 times

6

What’s the difference between scheduleAtFixedRate and schedule?

I am developing an Android app that I want to be 50 minutes late before starting an action and repeat that action in the next 50 minutes, but I would like to know which one will satisfy my need, in this case.

  • I believe that AtFixedRate either for repetitions, because it implies a frequency (scheduleAtFixedRate = scheduleA_TaxaFixa). "_" was to respect camelCase :D

  • Okay ... Thank you :)

  • If you have solved the question, let me know and I will turn the comment into a reply.

1 answer

2

The difference between these methods is as follows:

Scheduledexecutorservice.Chedule

When calling this method you must define a Runnable which is your task, the team that the action should be executed and the Timeunit(if and hoars, minutes, etc). This method will execute what we call one-shot action. Your runnable will run only once at set time. (there are overloaded versions that accept Calleables instead of Runnables)

ScheduledExecutorService.scheduleAtAFixedRate

Already on the call of scheduleAtAFixedRate m[etodo Creates and executes an action - Runnable/Callable periodic which is activated for the first time after the initial delay given. If any execution of the task of casting an exception, subsequent executions are suppressed, ie are not performed. Otherwise, the task will only end via cancellation or shutidown of the executor.

Pay attention to this detail:

If any execution of this task takes longer than your period, then subsequent executions may be triggered later, but there will be no execution simultany.

Please take a look at the Javadocs

http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.