首页 > 其他 > 详细

单例模式

时间:2018-09-08 10:49:43      阅读:203      评论:0      收藏:0      [点我收藏+]
 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 }

 

单例模式

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!