JavaMemoryModel: singleton q-of-week

From: Joseph Bowbeer (jozart@csi.com)
Date: Sun Nov 19 2000 - 19:36:45 EST


The answer to the singleton question-of-the-week has been corrected, but
I'm wondering if the correction is thread-safe. Is a synchronized
getInstance method or a HelperSingleton needed? Or is the following OK?

http://developer.java.sun.com/developer/qow/archive/111/index.html

public class Singleton {
    private static final Singleton INSTANCE =
                              new Singleton();

   // Private constructor supresses
   // default public constructor
    private Singleton( ) {
    }

    public static Singleton getInstance( ) {
        return INSTANCE;
    }
 }

--
Joe Bowbeer

------------------------------- JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:28 EDT