[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:25:41 EDT 2006


I need one more name (email address fine) of somebody who has carefully 
examined this example and judged it to be the right thing for Mustang. 
Send this directly to me, not to the list, please. If there's anything 
to report back I'll be sure to do that.

Thanks,
Pete

Pete Soper wrote:
> Recently the "SerialNum" example class in the java.lang.ThreadLocal doc 
> was upgraded to use autoboxing and generics and to avoid unclear use of 
> "synchronized." We (some JSR166 expert group members and I) thought this 
> new version looked pretty good, but Tom Hawtin thought otherwise, 
> pointing out the value of using @Overload, "final" and 
> getAndIncrement(). That he found three ways to improve this was a bit of 
> a surprise and suggests the more eyes the better, so I'm asking for any 
> additional comments for the new version listed below. This is the raw 
> text and the escape sequences of course display as "<" and "@" as HTML. 
> Note also the two long lines format fine despite the autowrap your mail 
> client might show below.
> 
> -Pete
> 
> ----
>   * <pre>
>   * import java.util.concurrent.atomic.AtomicInteger;
>   *
>   * public class SerialNum {
>   *
>   *     // The next serial number to be assigned. Starts at zero.
>   *     private static final AtomicInteger nextSerialNum = new 
> AtomicInteger();
>   *
>   *     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>
> 
> 
> 
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
> 



More information about the Concurrency-interest mailing list