zoukankan      html  css  js  c++  java
  • 单例

    /** 线程安全,但效率低  懒汉,线程安全

    private static ImAddressPool instance = null;

    private ImAddressPool() {}

    public synchronized static ImAddressPool getInstance() {

    if (instance == null) {

    instance = new ImAddressPool();

    instance.init();

    }

    return instance;

    }

    **/

    // 类装载时就实例化 饿汉

    /***

    private static ImAddressPool instance = new ImAddressPool();

    private ImAddressPool() {

    init();

    }

    public static ImAddressPool getInstance() {

    return instance;

    }

    **/

     

     

    // 内部静态类方式

    private static class SingletonHolder {

    private static final ImAddressPool INSTANCE = new ImAddressPool();  

    }  

    private ImAddressPool (){

    init();

    }

     

    public static final ImAddressPool getInstance() {  

    return SingletonHolder.INSTANCE;  

    }  

  • 相关阅读:
    500. 键盘行
    657. 判断路线成圈
    771. 宝石与石头
    461. 汉明距离
    Java 基本数据类型
    Windows下的DOM操作
    jQuery学习笔记
    Java(16-19)
    Java(1-15)
    总结
  • 原文地址:https://www.cnblogs.com/hujihon/p/4834624.html
Copyright © 2011-2022 走看看