addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1light-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [ljc] JVM is messed up when system clock is rolled backward

From: Richard W.
Sent on: Monday, September 2, 2013 10:24 AM

thanks for your answer, I am happy to provide you answers. I was just thinking about all these Java deamons in the world, running on 64bit VM+Linux, and what happens when the daylight saving switch is turned on or off... funny eh?

I think there's a bit of confusion.  There are two views of time in computer systems:  the machine view and the human view.  The machine view defines a timeline in terms of some underlying units: at some level this become clocking events in a CPU.  The human view decorates this timeline with many social and administrative constructs: such as days, weeks, months, years and timezones.

A timezone defines certain rules about the number of hours it is offset from UTC.  Daylight savings are merely a switch in those rules. Daylight savings time going backwards an hour doesn't change the machine timeline's view of the world.  All it does is mean that instead of being offset from UTC by N hours you are offset by M hours, usually M is N + 1 or N - 1 but that's isn't always the case.

This means that the situation that you've outlined where a daylight savings time causes System.nanoTime() to change isn't going to happen.  That's not to say that time can't go backwards, as Martijn has mentioned your NTP server can reset the time. The System.nanoTime() implementation on linux is properly synchronised between cores so you don't need to worry about the difference between TSC between cores causing non-monotonicity.

In case people are worrying about leap seconds being negative: they can be, but there's are multiple defined timelines which avert this problem the most standardised of which is UTC-STS.  Of course very few people use this, but backing Java 8's new date and time library onto UTC-STS is possible.

tl;dr take care when changing or reset the system clock, but don't worry so much about the daylight saving switch.


  Dr. Richard Warburton

Our Sponsors

  • Our Blog

    Read the latest news from the LJC

  • RecWorks Ltd

    Fixing Tech Recruitment using the Power of Community

  • jClarity

    Java/JVM Performance Analysis Tools & mentoring for Java related matters

  • LJC Aggrity

    Our LJC Aggrity site contains blog posts from our members

  • LJC Book Club

    Our Book club with book reviews from our members

  • Devoxx UK

    Java Community Conference in collaboration with the LJC, 8-10th June 16

  • SkillsMatter

    "Host, help organise, promote, film many of our meetings."

  • IBM

    Build Enterprise-grade apps at start-up speed.

  • New Relic

    New Relic makes sense of billions of metrics a day in real time.

  • Hazelcast

    Hazelcast is the leader in operating in-memory computing.

  • Java.Net

    We are an official Java User Group recognised by Oracle's JUG program

  • JRebel

    Free 3 month J-Rebel license.

  • O'Reilly

    40% discount on printed books and 50% on e-books.

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy