1 Reply Latest reply on Dec 12, 2011 8:52 PM by 880401

    Why you shouldn't use TimerTask.

      At the Devoxx 2011 conference there was a talk by Ben Evans and Martijn Verburg.

      On one of the slides (that where skipped) there was a bullet:
      "Stop using timerTask"
      Does anyone have any idea why they would state this?
        • 1. Re: Why you shouldn't use TimerTask.
          One reason, among many, is that TimerTask uses the System.currentTimeMillis() method to define all of it's execution scheduling.

          The call to System.currentTimeMillis() is providing the host computers representation of 'Wall Time' and does not behave very well when the system clock is adjusted such as when NTP or similar makes adjustments to the clock.

          This is especially a problem with large periods between scheduled executions and the system clock is adjusted in large steps.

          Or even with short periods, as long as the clock adjustments are large compared to the execution period.

          This issue is just one of the many that cause issues with this facility.

          There are better solutions, coded to deal with the multitudinous issues of scheduled tasks in the real world; you are better off using the 'concurrency' package rather than the Timer and TimerTask from the util package.