zoukankan      html  css  js  c++  java
  • 单例模式之一

     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 }
  • 相关阅读:
    第一个SWT程序
    稀疏数组
    算法与数据结构
    《Java核心技术》学习笔记 第1-3章
    算术运算符
    5.11 rw zip file
    5.10 gob序列化
    5.9 piping between writer and reader
    5.7 io.MultiWriter(buf, f)
    5.7 读写 二进制数据
  • 原文地址:https://www.cnblogs.com/jimw/p/4843377.html
Copyright © 2011-2022 走看看