This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Problem with java.util.Timer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem with java.util.Timer" Watch "Problem with java.util.Timer" New topic
Author

Problem with java.util.Timer

Usman Usmani
Greenhorn

Joined: Jun 13, 2005
Posts: 4
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
Sheriff

Joined: Sep 28, 2004
Posts: 18532
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with java.util.Timer
 
Similar Threads
problem with scheduling in JBOSS
Trouble with Prometric ..
Auto Notification - Email
problem with scheduling in JBOSS
Essay exam scheduled in advance?