hg: lambda/lambda/jdk: Summary: add ThreadLocal(Factory<T>) and compareAndSet methods

Doug Lea dl at cs.oswego.edu
Tue Jul 31 05:59:39 PDT 2012


On 07/31/12 08:41, Aleksey Shipilev wrote:
> On 07/31/2012 04:10 PM, David Holmes wrote:
>> On 31/07/2012 8:35 PM, Aleksey Shipilev wrote:
>>> Please make sure you have both versions in place (i.e.
>>> updateAndGet/getAndUpdate). Also, while you are at it, can you also add
>>> the updaters for AtomicReference and friends?
>>
>> What do you mean? What can you do to a reference other than set it?
>
> Transform, given the current state? Trivial case:
>
>     private class Holder {
>         int x;
>         int y;
>     }
>
>     private AtomicReference<Holder>  holder = ...;
>
>     holder.updateAndGet(h ->  new Holder(h.x + 1, h.y + 1));
>
> Is this too much to ask? :)

This accentuates the "moral hazard" issue I mentioned.
What is the motivation for incorporating into JDK convenience methods to
support a technique with such a restricted range of applicability?
On contention, this method will not only eat a lot of cycles but
also spew a lot  of garbage. Sometimes this is a good choice anyway.
We use it occasionally in java.util.concurrent, but never without
exploring alternatives. I don't think that even we use it enough
to justify writing our own lambdafied version (which anyone can
do if they do end up using it a lot).

-Doug



More information about the lambda-dev mailing list