/** * @author Ronald Koster */ public class Singleton { private static Singleton instance = null; private Singleton() {} /** * This is a class (static) method. So this should work in a multi-threaed environment as well. See the * "The Java Language Specification - Second Edition", section "synchronized Methods": For a class (static) method, * the lock associated with the Class object for the method's class is used. For an instance method, the lock associated with * this (the object for which the method was invoked) is used. */ public static synchronized Singleton getInstance() { if (instance == null) { instance = new Singleton(); } return instance; } }