}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package factory; /** * 懒汉式工厂 * * @ClassName: Factory2.java * @Description: 不立即生成,存在线程不安全,所以上同步锁 * @Author lyf * @Date 2017年3月10日 上午9:35:43 * */ public class Factory2 { private Factory2() { } private static Factory2 factory2 = null; private synchronized static Factory2 getInstance() { if (factory2 == null) { factory2 = new Factory2(); } return factory2; } }
