当前位置:编程学习 > 网站相关 >>

多线程安全 Singleton

 

<span style="font-size:24px;">/**

 *

 * @author chunxiao

 * @version 1.0

 */ 

public class Singleton { 

     

    private Singleton() { 

    } 

     

    public static Singleton getInstance() { 

        return SingletonHolder.INSTANCE; 

    } 

     

    private static class SingletonHolder { 

 

        private static final Singleton INSTANCE = new Singleton(); 

    } 

}</span> 

 

lazy loading版本的线程安全单例模式

 

 

作者 rjgcx2

补充:综合编程 , 安全编程 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,