• Post Reply Bookmark Topic Watch Topic
  • New Topic

TimerTask delay shorter than the time it task to execute the run() method

 
Andrei Antonescu
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I am having a timertask set to be executed at every 1 second.
The task it's programmed to do smth that could sometimes take longer than 1 second.
Will a second call to run() start even if the first hasn't finished executing run() (in case the 1 second delay has elapsed)?

Thanks in advance
 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are executing using a Timer, then the first task will complete, and only then will the second one be started. If your tasks take longer than the delay between tasks, then either the next task will start immediately, or it will simply wait for the delay, depending on whether you used schedule() or scheduleAtFixedRate().

Regardless, your task should not take this long. Timer expects short tasks that execute quickly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!