java timer task schedule

From reading on Stack Overflow I've seen that many of you don't recommend using Timer Task. Hmmm... but I already implemented this:

I have this code:

detectionHandlerTimer.schedule(myTimerTask, 60 * 1000, 60 * 1000);

The thing is that work of myTimerTask lasts some time.

I would like this behavior:

  1. wait 60 sec.
  2. do task for some time (e.g. 40 - 100 sec).
  3. task finished.
  4. wait 60 seconds.
  5. do task for some time (e.g. 40 - 100 sec).

But the code above behaves like this

  1. wait 60 sec.
  2. do task for some time (e.g. 40 - 100 sec).
  3. task finished
  4. do task for some time (e.g. 40 - 100 sec).

Because the time duration of task is bigger than 60, timer starts task immediately after task is finished. But I would like it to wait again.

5
задан Rob Hruska 28 October 2010 в 16:37
поделиться