黑马程序员 延迟加载的单例设计模式

上一篇 / 下一篇  2014-07-08 14:03:16 / 个人分类:java知识


单例设计模式:要求内存中只能存在一个对象,不能用new方法创建对象 ,只能用类名调用静态方法产生对象。

class single{
 
 private single(){}; 

 private static single s=null;
 public static single getinstance()
 {
  if(s==null)
   synchronized (single.class){
    
   if(s==null)
   s=new single();
   }
  return s;
 } 
}

class singleDemo
{
 public static void main(String[] args)
 {
  single ss=single.getinstance();
  ss.getinstance();
 }
 
}


TAG:

 

评分:0

我来说两句

日历

« 2024-05-08  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 6605
  • 日志数: 16
  • 建立时间: 2013-12-02
  • 更新时间: 2014-07-14

RSS订阅

Open Toolbar