public class Singleton {
//单例设计模式,禁止指令重排可以加volatile
private static Singleton singleton = null;
private void Singleton() {
System.out.println(Thread.currentThread().getName() + "构造方法执行");
}
//DCL(Double Check lock双端检索机制)
public static Singleton getInstance() {
if (singleton == null) {
synchronized (Singleton.class) {
if (singleton == null) {
singleton=new Singleton();
}
}
}
return singleton;
}
}