首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

双重锁定的单例种

2012-09-13 
双重锁定的单例类public class Singleton {private static Singleton instanceprivate staticObject sync

双重锁定的单例类

public class Singleton {private static Singleton instance;private static  Object syncRoot = new Object();private Singleton() {}public static Singleton getInstance(){if(instance == null){synchronized (syncRoot) {if(instance == null){instance = new Singleton();}}}return instance;}

?

线程安全下的单例类 ,双重锁定哦 ?

?

?

热点排行