JDK-6741261 : java.lang.Thread should utilize Atomics for global counters
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2008-08-26
  • Updated: 2010-12-10
  • Resolved: 2010-12-10
Description
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.

Comments
EVALUATION It turned out that this could not be done due to initialization problems. The Thread class is one of the first to be initialized and can only have very limited dependencies. The Atomic classes create reflective objects during their initialization and this fails if attempted while Thread is not yet initialized.
08-12-2010

EVALUATION See description.
26-08-2008