Thanks for the clarification.
So a synchronized getInstance method is only needed for lazy
instantiation.  Makes sense.
The HelperSingleton class on the no-double-check page still confuses me,
though.  When does this come into play?
----- Original Message -----
From: "Bill Pugh" <pugh@cs.umd.edu>
To: "JMM" <javaMemoryModel@cs.umd.edu>
Sent: Sunday, November 19, 2000 5:43 PM
Subject: Re: JavaMemoryModel: singleton q-of-week
This is perfectly OK. The JLS and JVM require that a class be
initialized before any static fields or methods of that class are
accessed, and that the JVM perform appropriate synchronization so
that any thread accessing a class see all of the results of that
initialization.
Bill
At 4:36 PM -0800 11/19/00, Joseph Bowbeer wrote:
>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;
>     }
>  }
>
-------------------------------
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