private static DateTime uniqueTimestamp ( ) { long currentMillis ; synchronized ( FixedUidGenerator . class ) { currentMillis = System . currentTimeMillis ( ) ; // guarantee uniqueness by ensuring timestamp is always greater // than the previous.. if ( currentMillis < lastMillis ) { currentMillis = lastMillis ; } if ( currentMillis - lastMillis < Dates . MILLIS_PER_SECOND ) { currentMillis += Dates . MILLIS_PER_SECOND ; } lastMillis = currentMillis ; } final DateTime timestamp = new DateTime ( currentMillis ) ; timestamp . setUtc ( true ) ; return timestamp ; }
Generates a timestamp guaranteed to be unique for the current JVM instance .