Difference between delay and period parameters of scheduleAtFixedRate() function of Timer in java

SteffyK picture SteffyK · Aug 4, 2015 · Viewed 7.4k times · Source

In java.util.Timer.scheduleAtFixedRate(TimerTask timer, long delay, long period), what is the difference between delay and period?

Answer

hoijui picture hoijui · Aug 4, 2015

For such things, always see the (Java SDK) JavaDocs: https://docs.oracle.com/javase/8/docs/api/java/util/Timer.html#scheduleAtFixedRate-java.util.TimerTask-long-long-

delay - delay in milliseconds before task is to be executed.
period - time in milliseconds between successive task executions.

(Your IDE should also show it to you automatically)

So delay is the time from now till the first execution, and after that it executes every period milliseconds again.

An other good way to find out: Use two different values for delay and period, and a TimerTask that just prints a line to the console. Then see what happens.