public class UUIDTimer
- extends java.lang.Object
UUIDTimer produces the time stamps required for time-based UUIDs.
It works according to UUID-specification, with following
- Java libs can only product time stamps with maximum resolution
of one millisecond. To compensate, an additional counter is used,
so that more than one UUID can be generated between java clock
updates. Counter may be used to generate up to 10000 UUIDs for
each distrinct java clock value (which in some cases may mean
getting 10k UUIDs for each 55 msecs, a la Windows, ie only
about 200000 UUIDs per second).
- An additional precaution, counter is initialized not to 0
but to a random 8-bit number, and each time clock changes, lowest
8-bits of counter are preserved. The purpose it to make likelyhood
of multi-JVM multi-instance generators to collide, without significantly
reducing max. UUID generation speed. Note though that using more than
one generator (from separate JVMs) is strongly discouraged, so
hopefully this enhancement isn't needed.
This 8-bit offset has to be reduced from total max. UUID count to
preserve ordering property of UUIDs (ie. one can see which UUID
was generated first for given UUID generator); the resulting
9500 UUIDs isn't much different from the optimal choice.
Some additional assumptions about calculating the timestamp:
- System.currentTimeMillis() is assumed to give time offset in UTC,
or at least close enough thing to get correct timestamps. The
alternate route would have to go through calendar object, use
TimeZone offset to get to UTC, and then modify. Using currentTimeMillis
should be much faster to allow rapid UUID creation.
- Similarly, the constant used for time offset between 1.1.1970 and
start of Gregorian calendar is assumed to be correct (which seems
to be the case when testing with Java calendars).
|Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public UUIDTimer(java.security.SecureRandom rnd)
public void getTimestamp(byte uuidData)
Copyright © 2003 MBARI.
The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.