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

(thread spec) Modernize ThreadLocal code example

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 6
    • 6
    • core-libs
    • None
    • generic
    • generic

      The code example "SerialNum" in the class comment for ThreadLocal
      can be better written using modern Java idioms:

      class SerialNum {
          private static ThreadLocal<Integer> serialNum
      = new ThreadLocal<Integer>()
          {
      // The next serial number to be assigned
      private int nextSerialNum = 0;

      protected synchronized Integer initialValue() {
                  return nextSerialNum++;
              }
          };

          public static int get() {
              return serialNum.get();
          }
      }

            psoper Pete Soper (Inactive)
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: