[concurrency-interest] Need one more reviewer, please Re: new SerialNum example for ThreadLocal class doc

Pete Soper Pete.Soper at Sun.COM
Thu Jun 8 12:45:34 EDT 2006


tim at peierls.net suggested "Why not remove 'Starts at zero' and give an 
explicit 0 argument to the AtomicInteger constructor?" and I said I 
think this is a good idea. It's incorporated below. Any more comments 
(direct to me, please)?

-Pete

----
   * <pre>
   * import java.util.concurrent.atomic.AtomicInteger;
   *
   * public class SerialNum {
   *
   *     private static final AtomicInteger nextSerialNum = new 
AtomicInteger(0);
   *
   *     private static final ThreadLocal&lt;Integer> serialNum = new 
ThreadLocal&lt;Integer>() {
   *         &#64;Override
   *         protected Integer initialValue() {
   *             return nextSerialNum.getAndIncrement();
   *         }
   *     };
   *
   *     public static int get() {
   *         return serialNum.get();
   *     }
   * }</pre>





More information about the Concurrency-interest mailing list