码迷,mamicode.com
首页 > 其他好文 > 详细

单例模式

时间:2018-09-08 11:46:34      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:==   eth   vat   pre   turn   volatile   null   bsp   style   

 1 public class Singleton {
 2 
 3     private Singleton(){
 4         //do something
 5     }
 6 
 7     private static volatile Singleton singleton = null;
 8 
 9     public static Singleton getInstance(){
10         if (singleton == null){
11             synchronized (Singleton.class){
12                 if (singleton == null){
13                     singleton = new Singleton();
14                 }
15             }
16         }
17         return singleton;
18     }
19 }

 

单例模式

标签:==   eth   vat   pre   turn   volatile   null   bsp   style   

原文地址:https://www.cnblogs.com/yumingxing/p/9608047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!