//懒汉式,线程安全
public class Singleton5 {private static volatile Singleton5 singleton;private Singleton5(){}//双重检查public static Singleton5 getInstance(){if(singleton == null){synchronized (Singleton5.class){if ((singleton == null)){singleton = new Singleton5();}}}return singleton;}public static void main(String[] args) {Singleton5 instance1 = Singleton5.getInstance();Singleton5 instance2 = Singleton5.getInstance();System.out.println(instance1 == instance2);System.out.println("****");System.out.println(instance1.hashCode());System.out.println(instance2.hashCode());}
}