标签:
单例模式:饿汉式单例类 懒汉式单例类
饿汉式和单例式区别
1 /** 2 * 懒汉式单例模式 3 * @author Administrator 4 * 5 */ 6 public class Singleton{ 7 private static Singleton _instance = null; 8 9 //构造方法私有,保证外界无法直接实例化 10 private Singleton(){ 11 12 } 13 14 //方法同步 15 synchronized public static Singleton getInsatance(){ 16 if(_instance == null){ 17 _instance = new Singleton(); 18 } 19 20 return _instance; 21 } 22 23 }
标签:
原文地址:http://www.cnblogs.com/wangwanchao/p/4977704.html