标签:
/**
*具体说明见 http://www.cnblogs.com/coffee/archive/2011/12/05/inside-java-singleton.html
*/
package com.work.pattern; public class Singleton2 {
private static Singleton2 instance = new Singleton2(); private Singleton2(){ } public static Singleton2 getInstance(){ return instance; } }
package com.work.pattern; /** * 单例模式创新!google的ioc作者写的。只有在调用的时候才会初始化!而且线程安全 * 超级牛! * */ public class Singleton { static class SingletonHolder { static Singleton instance = new Singleton(); } public static Singleton getInstance() { return SingletonHolder.instance; } }
标签:
原文地址:http://www.cnblogs.com/bendantuohai/p/4743320.html