public static String getUid ( ) { /* Unique down to millisecond */ short hiTime = ( short ) ( System . currentTimeMillis ( ) >>> 32 ) ; int loTime = ( int ) System . currentTimeMillis ( ) ; int ct ; synchronized ( Uid . class ) { if ( counter < 0 ) { counter = 0 ; } ct = counter ++ ; } return new StringBuilder ( 36 ) . append ( format ( IP ) ) . append ( sep ) . append ( format ( JVM ) ) . append ( sep ) . append ( format ( hiTime ) ) . append ( sep ) . append ( format ( loTime ) ) . append ( sep ) . append ( format ( ct ) ) . toString ( ) ; }
Code copied and modified from hibernate UUIDHexGenerator . Generates a unique 36 character key of hex + separators .