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

Head First设计形式-单例模式

2013-10-16 
Head First设计模式-单例模式一、整体代码Singleton.javapublic class Singleton {private static Singleto

Head First设计模式-单例模式

一、整体代码

        Singleton.java

public class Singleton {private static Singleton uniqueInstance = new Singleton();; // other useful instance variables here private Singleton() {} public static Singleton getInstance() {return uniqueInstance;} // other useful methods here}
 

二、解析

      1、第一种单件模式,在多线程时需要同步,造成了额外开销。

       2、第二种不用同步。


热点排行