总结出来的经验,共享给大小,欢迎有更好的设计,补充~
/**
* 线程同步并且效率高
*
*/
public class SingletonTest {
private static SingletonTest instance;
private SingletonTest() {
}
public static SingletonTest getIstance() {
if (instance == null) {
synchronized (SingletonTest.class) {
if (instance == null) {
instance = new SingletonTest();
}
}
}
return instance;
}
}
/**
* 线程异步
*
*/
public class SingletonTest {
private SingletonTest() {
}
private static SingletonTest instance;
public static SingletonTest getInstance() {
if (instance == null)
instance = new SingletonTest();
return instance;
}
}
Q群:426554356 java 技术交流群,欢迎大家加入,另有多多职位,HR美女喔