public T get ( ) { long expiration = whenItExpires ; long now = System . nanoTime ( ) ; // if uninitialized or expired update value if ( expiration == 0 || now >= expiration ) { synchronized ( this ) { // ensure a different thread didn't update it if ( whenItExpires == expiration ) { whenItExpires = now + durationNanos ; try { value = getter . call ( ) ; } catch ( Exception e ) { // shouldn't happen throw Throwables . propagate ( e ) ; } } } } return value ; }
Get or refresh and return the latest value .