packageidv.design.pattern.singleton.lazy;/** * @author Carl Lu */publicclassSingleton {/* * This is also called "optimistic lock singleton". *//* * Define a variable for saving instance that will be build. */privatestaticSingleton uniqueInstance =null;/* * The constructor should be private so that we can control the instance number. */privateSingleton() { }/* * Need to define a method for providing class instance to clients. * To ensure thread-safe, please add keyword synchronized in the method declaration. * * @return Singleton singleton instance */publicstaticsynchronizedSingletongetInstance() {if (uniqueInstance ==null) { uniqueInstance =newSingleton(); }return uniqueInstance; }publicvoidsingletonOperation() {System.out.println("Do something here..."); }}