[concurrency-interest] How seriously should we take broken double
pugh at cs.umd.edu
Tue May 3 11:42:45 EDT 2005
Please tell me what project you work on so I can avoid it, or what
company you work for so I can short your stock.
Like others, I am appalled at your tech lead's attitude towards
There is essentially no cost to performing thread-safe lazy
initialization in a correct way, and several
possible correct ways to accomplish it.
If it really is that case that your objects have no instance fields
at all, they you can get away with the non-thread-safe form
of double checked locking. But that is very much a corner case, and
would break if you ever added fields to those objects.
Also, if the objects truely have no state, I can't see that you are
saving much of anything by initializing them in a lazy fashion.
On May 2, 2005, at 8:59 PM, Unmesh joshi wrote:
> 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 system".
> 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!
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
More information about the Concurrency-interest