public class Singleton1 {
private static Singleton1 instance = null;
private Singleton1() {
}
public static Singleton1 getInstances() throws InterruptedException {
if (instance == null) { //为了优化,当instance不为空是,直接返回实例对象
synchronized (Singleton1.class) {
if (instance == null) {
Thread.sleep(100);
instance = new Singleton1();
}
return instance;
}
}
return instance;
}
}