java.lang.Thread uses two global counters: /* For autonumbering anonymous threads. */ private static int threadInitNumber; private static synchronized int nextThreadNum() { return threadInitNumber++; } /* For generating thread ID */ private static long threadSeqNumber; private static synchronized long nextThreadID() { return ++threadSeqNumber; } both of these should have been updated in Java 5 to take advantage of the j.u.c AtomicInteger/AtomicLong classes to avoid contention on the Thread Class object's monitor.
|