标签:
1 class Singelton { 2 private static singleton instance; 3 //构造方法让其private,这就封住了外界利用new创建实例的可能 4 private Singleton(){} 5 6 //该方法是活的哥本类实例的唯一全局访问点 7 public static Singleton GetInstance(){ 8 9 //若实例不存在,则new一个新实例,否则返回已有的实例 10 if (instance == null){ 11 instance=new Singleton() 12 } 13 14 return instance ; 15 16 } 17 }
1 //实现赖式单态类 2 private static ControlConfigurationFiles object = null; 3 4 public static synchronized ControlConfigurationFiles getInstance(ServletContext context) { 5 //获取web项目中ccs的配置文件 6 ControlConfigurationFiles.filePath = context.getRealPath("/WEB-INF/classes/ccs.properties"); 7 8 if (object == null) { 9 object = new ControlConfigurationFiles(ControlConfigurationFiles.filePath); 10 } 11 12 return object; 13 }
标签:
原文地址:http://www.cnblogs.com/jimw/p/4843377.html