标签:throw get 同步代码块 file gets syn sts main desc
?? //单例模式之懒汉式 class Singleton{ private static Singleton instance = null; private Singleton(){ } public static Singleton getSingleton(){ if(instance == null){ //同步代码块,保证安全性 synchronized(Singleton.class){ if(instance == null){ instance = new Singleton(); } } } return instance; } } public class TestSingleton { /** * @Title: main * @Description: * @param: * @return void * @user: wangzg * @Date:2014-10-27 * @throws */ public static void main(String[] args) { // TODO Auto-generated method stub Singleton singleton1 = Singleton.getSingleton(); Singleton singleton2 = Singleton.getSingleton(); System.out.println(singleton1 == singleton2); } }
标签:throw get 同步代码块 file gets syn sts main desc
原文地址:http://www.cnblogs.com/claireyuancy/p/7257392.html