Error in ThreadLocal javadoc example

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: 6u24
    • Component/s: core-libs
    • x86
    • windows_7

      FULL PRODUCT VERSION :


      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 64 bit

      A DESCRIPTION OF THE PROBLEM :
      For example, the class below generates unique identifiers local to each thread. A thread's id is assigned the first time it invokes UniqueThreadIdGenerator.getCurrentThreadId() and remains unchanged on subsequent calls.

       import java.util.concurrent.atomic.AtomicInteger;

       public class UniqueThreadIdGenerator {

           private static final AtomicInteger uniqueId = new AtomicInteger(0);

           private static final ThreadLocal < Integer > uniqueNum =
               new ThreadLocal < Integer > () {
                   @Override protected Integer initialValue() {
                       return uniqueId.getAndIncrement();
               }
           };
       
           public static int getCurrentThreadId() {
               return uniqueId.get(); /*** Should be uniqueNum.get() ***/
           }
       } // UniqueThreadIdGenerator




      REPRODUCIBILITY :
      This bug can be reproduced always.

            Assignee:
            Unassigned
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: