packageidv.design.pattern.singleton.eager;/** * @author Carl Lu */publicclassSingleton {/* * This is also called "pessimistic lock singleton". *//* * Define a variable for saving instance, new the instance here. * The JVM will guarantee that the class will be instantiated for only one time, * so this way is thread-safe. */privatestaticfinalSingleton uniqueInstance =newSingleton();/* * 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. * * @return Singleton singleton instance. */publicstaticSingletongetInstance() {return uniqueInstance; }}