While scheduling tasks using java.util.TimerTask how i can make sure that run method will execute only after current execution is completed, otherwise tasks queue size will keep growing and eventually task will be executing always. i am beginner and looking help
Asked
Active
Viewed 269 times
2 Answers
1
Use ExecutorService#scheduleWithFixedDelay(). This will start the 'delay' when the current task finishes (as opposed to scheduleAtFixedRate())
Wim Deblauwe
- 22,652
- 17
- 122
- 191
1
Use a java.util.Timer with the TimerTask. One of these timer's two methods can be used:
schedule(TimerTask task, long delay, long period)scheduleAtFixedRate(TimerTask task, long delay, long period)
Where:
task - task to be scheduled.
delay - delay in milliseconds before task is to be executed.
period - time in milliseconds between successive task executions.
Also, refer this article: What is the difference between schedule and scheduleAtFixedRate?
prasad_
- 11,128
- 2
- 21
- 30