Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7027197

Error in ThreadLocal javadoc example

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u24
    • 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.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: