On 05/13/2012 02:24 AM, Jacques Le Roux wrote: > From: "Adam Heath" <doo...@brainfood.com> >> Sure, volatile makes DCL *safe*, but it is still slower, in the case >> when the initial fetch is null. For static initialization, it might >> be ok to use it. But it's probably more confusing to unaware java >> programmers(using volatile+DCL). Using CAS-type mechanisms makes it >> more explicit what is actually occuring. >> >> And, when DCL is used against map-type(or collection-type) systems, >> where the value could go away at any time, removing DCL can actually >> make things faster, as you are reducing contention. > > Yes using volatile with DCL is defintitvely slower. What do you call > CAS-type?
java.util.concurrent.atomic.* for instance. The sun jdk jit compiler actually detects calls to those objects, and replaces them with low-level asm calls instead. No object overhead. volatile effectively means no cpu-caching on die. > Jacques