public class TestSingleton {
private static TestSingleton instance;
private TestSingleton() {}
public static TestSingleton getInsatance() {
if(instance == null){
//TestSingleton.class锁住的是字节码文件
synchronized (TestSingleton.class) {
if(instance == null){
instance = new TestSingleton();
}
}
}
return instance;
}