java设计模式之单例模式(加锁的懒汉)

package src.test.java.com.pbc.singleton;
/**
 * (加锁的懒汉式)单例模式
 * @author qiu_y
 *
 */
public class SingletonLock {
 private static SingletonLock singletonLock = null;
 /**
  * 私有构造器
  */
 private SingletonLock() {}
 /**
  * 加锁的懒汉式单例
  * 1.相比较懒汉式更加线程安全,缺由于加锁导致额外消耗
  */
 public static SingletonLock getInstance() {
  synchronized (SingletonLock.class) {
   if (null == singletonLock) {
    singletonLock = new SingletonLock();
   }
  }
  return singletonLock;
 }
}
posted @ 2020-07-03 17:07  尚进生  阅读(654)  评论(0编辑  收藏  举报