java设计模式之单例模式(双重加锁懒汉)
package src.test.java.com.pbc.singleton;
/**
* (双重加锁懒汉)单例模式
* @author qiu_y
*
*/
public class DoubleLockSingleton {
private static DoubleLockSingleton doubleLockSingleton = null;
/**
* 私有构造器
*/
private DoubleLockSingleton() {}
/**
* 双重加锁懒汉单例
* 懒加载,线程安全,效率高
*/
public static DoubleLockSingleton getInstince() {
if(null == doubleLockSingleton) {
synchronized (DoubleLockSingleton.class) {
if (null == doubleLockSingleton) {
doubleLockSingleton = new DoubleLockSingleton();
}
}
}
return doubleLockSingleton;
}
}
* (双重加锁懒汉)单例模式
* @author qiu_y
*
*/
public class DoubleLockSingleton {
private static DoubleLockSingleton doubleLockSingleton = null;
/**
* 私有构造器
*/
private DoubleLockSingleton() {}
/**
* 双重加锁懒汉单例
* 懒加载,线程安全,效率高
*/
public static DoubleLockSingleton getInstince() {
if(null == doubleLockSingleton) {
synchronized (DoubleLockSingleton.class) {
if (null == doubleLockSingleton) {
doubleLockSingleton = new DoubleLockSingleton();
}
}
}
return doubleLockSingleton;
}
}