hg: lambda/lambda/jdk: Summary: add ThreadLocal(Factory<T>) and compareAndSet methods
Aleksey Shipilev
aleksey.shipilev at oracle.com
Tue Jul 31 06:42:15 PDT 2012
On 07/31/2012 04:59 PM, Doug Lea wrote:
> 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?
I would disagree about the "restricted" here. Any other way to have
multi-site atomicity? My experience tells me, people faced with multiple
updates would end up with locking, because "it feels cleaner" than to
expose the loop in the code. Asking users to provide the updater is
something we can do to lower that impedance.
> 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.
Even if this is abused, the CPU cycles spent in CAS'ed loop are easily
detectable by whatever naive profiler you have. Locks, on the other
hand, are notoriously hard to diagnose in full.
-Aleksey.
More information about the lambda-dev
mailing list