001package headfirst.singleton.dcl;
002
003//
004// Danger!  This implementation of Singleton not
005// guaranteed to work prior to Java 5
006//
007
008public class Singleton {
009        private volatile static Singleton uniqueInstance;
010
011        private Singleton() {}
012
013        public static Singleton getInstance() {
014                if (uniqueInstance == null) {
015                        synchronized (Singleton.class) {
016                                if (uniqueInstance == null) {
017                                        uniqueInstance = new Singleton();
018                                }
019                        }
020                }
021                return uniqueInstance;
022        }
023}