Using a static helper inner-class that constructs and holds your singleton 
eliminates the synchronization overhead and is safe and works across JVM 
versions.  This is the initialization on-demand holder pattern.

I believe they fixed DCL in Java 5 as long as you use volatile (by the way, 
I completely overlooked you mentioning setting the static instance to 
volatile in your previous post - so for Android your suggestion would work 
assuming you're ok with synchronization overhead) but since DCL was an 
anti-pattern years ago I've stopped using it anyway.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to