[concurrency-interest] How seriously should we take broken double checked idiom

Unmesh joshi unmesh_joshi at hotmail.com
Mon May 2 20:59:47 EDT 2005


Double checked idiom is not guaranteed to work in Java. How seriously should 
we take it? In my current project, there are lot of stateless service 
classes, which are designed to be singletons. My tech lead says, "We have to 
use double checked idiom, even if it is not guaranteed to work. It will work 
most of the times and not many concurrent users are going to access the 
What I understand as broken with the idiom is.
1. Our of order writes can write reference to the singleton instance field 
before calling constructor.
2. "Constructor" in java does following.
    1. It sets up object layout with TypeIno pointer.
    2. Sets up HashCode field in object layout.
    3. Sets up Lock related structures in object.
    4. Sets up and Initializes instance fields (which can be ignored in my 
case, as objects are stateless)

Constructor not being called, means none of the above takes place. If any 
other thread thinks object as constructed and tries to call any method on 
the object can show unpredictable behaviour.

Is my understanding right?


Bought a New Cellphone? 
http://adfarm.mediaplex.com/ad/ck/4686-26272-10936-265?ck=Register Sell your 
old one for a Great Price in eBay!

More information about the Concurrency-interest mailing list