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;
> }
> }
>
>--
>Joe Bowbeer
>
>
>
>-------------------------------
>JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
-------------------------------
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