4 Replies Latest reply: Oct 7, 2011 12:17 PM by Johnny_hunter RSS

    a typo (bug) in JDK 6 document about ThreadLocal

    Johnny_hunter
      Hello all: I think I found a typo(bug) in the JDK 6 document about ThreadLocal: http://download.oracle.com/javase/6/docs/api/java/lang/ThreadLocal.html

      This is how it looks like from its sample code
      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();
           }
       } // UniqueThreadIdGenerator
      In the method getCurrentThreadId,*uniqueId* should be replaced by uniqueNum.
      As a comparison, please see the docuement in JDK 7 http://download.oracle.com/javase/7/docs/api/java/lang/ThreadLocal.html

      Thanks, John

      Edited by: Johnny_hunter on Sep 12, 2011 3:02 PM

      Edited by: Johnny_hunter on Sep 12, 2011 3:05 PM