Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with java.util.Timer

 
Usman Usmani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


I have created a class foo that extends TimerTask and I schedule it
with java.util.Timer.ScheduleAtFixe�dRate() to schedule it. the problem
is that once the timer starts scheduling and i change system date and
time it behaves quite abnormally and starts firing every moment.


Any one knows a way arround this??
 
Henry Wong
author
Marshal
Pie
Posts: 20892
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a known problem with fixed rate scheduling. See JavaDoc...

In fixed-rate execution, each execution is scheduled relative to the scheduled execution time of the initial execution. If an execution is delayed for any reason (such as garbage collection or other background activity), two or more executions will occur in rapid succession to "catch up." In the long run, the frequency of execution will be exactly the reciprocal of the specified period (assuming the system clock underlying Object.wait(long) is accurate).


In any case, you should not be playing with the Time if you expect the Timer class to behave correctly... however, the schedule() with fix delay option doesn't have this problem.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic