public long getTimestamp ( ) { while ( true ) { long current = System . currentTimeMillis ( ) * 1000 ; long last = lastTimestampMicros . get ( ) ; long tstamp = last >= current ? last + 1 : current ; if ( lastTimestampMicros . compareAndSet ( last , tstamp ) ) return tstamp ; } }
This clock guarantees that updates for the same ClientState will be ordered in the sequence seen even if multiple updates happen in the same millisecond .