I’m writing an Android application that records audio every 10 minutes. I am using a Timer to do that. But what is the difference between schedule and scheduleAtFixedRate? Is there any performance benefit in using one over the other?
I’m writing an Android application that records audio every 10 minutes. I am using
Share
The difference is best explained by this non-Android documentation:
Fixed-rate timers (
scheduleAtFixedRate()) are based on the starting time (so each iteration will execute atstartTime + iterationNumber * delayTime).Fixed-delay timers (
schedule()) are based on the previous execution (so each iteration will execute atlastExecutionTime + delayTime).Aside from this, there is no difference. You will not find a significance performance difference, either.
If you are using this in a case where you want to stay synchronized with something else, you’ll want to use
scheduleAtFixedRate(). The delay fromschedule()can drift and introduce error.