Results 1 to 2 of 2
  1. #1
    SamInfo is offline Member
    Join Date
    Jan 2012
    Rep Power

    Default 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,

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Rep Power

    Default 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.
    How are you determining this? Like I said, if you were coding a virtual clock and set it's time using Sleep() or something like that, then this would be the expected result. Your clock would go fast or slow depending on current system load (since java's time values are at the mercy of when the JVM can get a scheduled time call in to the Host OS).

    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!

Similar Threads

  1. 24 hour clock to 12 hour clock project.
    By bs3ac in forum New To Java
    Replies: 4
    Last Post: 01-08-2013, 11:10 AM
  2. help with clock
    By Bimz in forum New To Java
    Replies: 1
    Last Post: 09-26-2011, 02:50 PM
  3. System Clock
    By sehudson in forum New To Java
    Replies: 2
    Last Post: 04-12-2011, 04:34 PM
  4. App runs on one system but not the other?
    By PMurph in forum New To Java
    Replies: 7
    Last Post: 11-15-2010, 04:53 AM
  5. Code compiles in/runs in IDE but not on UNIX system
    By Unclejunebug in forum New To Java
    Replies: 7
    Last Post: 10-08-2009, 09:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts