Results 1 to 2 of 2
Thread: System clock runs fast
- 01-12-2012, 05:38 PM #1Member
- Join Date
- Jan 2012
- Rep Power
System clock runs fast
I am running a java program on Windows XP. The problem is that whenever the code is being run, the system clock starts running fast and gains almost 10 seconds every 1 min.
- Checked the CMOS battery, it is fine. The problem is happening on multiple computers so that is not a problem. There is not virus issues as well otherwise it would not have happened on different computers
- There is a bug reported from sun that if you are using Thread.sleep with time interval not in multiples of 10ms this may happen. My code had sleep method used but all of them in multiple of 10ms and min of 1 second.
Bug ID: 4814012 System clock acceleration on Windows still exists
- The suggested solution was to use -XX:+ForceTimeHighResolution in parameters which i tried but that didnt solve the problem
- Now i have removed all thread.sleep methods from the code but the problem still exists
Can anyone help me out with this problem as this is causing inaccurate time in the system clock. I havent been able to find any solution to this problem on the internet.
Thanks and Regards,
- 01-13-2012, 05:48 AM #2
Re: System clock runs fast
Well, ok, so java does not guarentee timing by any sense of the word. Everything in java with regards to time is an "I'll try my best" and should be treated as approximate.
For example, if you intended for an app to run for 1 second by sleeping for 10 intervals of 100ms, you would get close but not-perfect results. This is not the way to handle timing in java.
Values from System.currentTimeMillis() should be reasonably accurate though, so to track elapsed time the best approach would be to mark down the current time at the start of application/method/loop whatever, and periodically subtract that time from the current time to see how much time has passed.
system clock starts running fast and gains almost 10 seconds every 1 min.
The proper way to code a digital clock would be to periodically compare the current time to the last saved time (like I mentioned above) and if 1000ms have elapsed, then increment the clock.
Does this make sense? If you posted a small code same that demonstrates the problem, it would be easier to suggest a solution!
- By bs3ac in forum New To JavaReplies: 4Last Post: 01-08-2013, 11:10 AM
- By Bimz in forum New To JavaReplies: 1Last Post: 09-26-2011, 02:50 PM
- By sehudson in forum New To JavaReplies: 2Last Post: 04-12-2011, 04:34 PM
- By PMurph in forum New To JavaReplies: 7Last Post: 11-15-2010, 04:53 AM
- By Unclejunebug in forum New To JavaReplies: 7Last Post: 10-08-2009, 09:35 AM