Sorry if this has been asked before. I can't seem to get to the archives.

In the source code for OJB I have noticed several uses of the Singleton
pattern. Mostly, the code is of then form,

<SingletonName> {

    private static <SingletonName> _instance;

    <SingletonName> getInstance() {
        if(_instance == null) {
            _instance = getNewInstance();
        }

        return _instance;
}

I am puzzled by this idiom because it has been documented as "broken" for
the Java memory model with respect to multi-thread applications.

http://www.javaworld.com/javaworld/javatips/jw-javatip67-p2.html states,
"Using lazy instantiation for a concrete Singleton is not only unnecessary
in Java, it's downright dangerous in the context of multithreaded
applications."

Ref:
http://www.javaworld.com/javaworld/javatips/jw-javatip67.html?
http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html
http://www.javaworld.com/javaworld/jw-05-2001/jw-0525-double.html


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to