zoukankan      html  css  js  c++  java
  • 单例模式

    单例模式:JVM只存在一个实例。

    特点:

    1.拥有单例对象引用属性

    2.私有的构造方法

    3.提供公用的对外方法来获取单例对象

    饿汉式简单实用,类加载就实例化了,并且是并发安全的。

    /**
     * Every Java application has a single instance of class
     * <code>Runtime</code> that allows the application to interface with
     * the environment in which the application is running. The current
     * runtime can be obtained from the <code>getRuntime</code> method.
     * <p>
     * An application cannot create its own instance of this class.
     *
     * @author  unascribed
     * @see     java.lang.Runtime#getRuntime()
     * @since   JDK1.0
     */
    public class Runtime {
        private static Runtime currentRuntime = new Runtime();
    
        /**
         * Returns the runtime object associated with the current Java application.
         * Most of the methods of class <code>Runtime</code> are instance
         * methods and must be invoked with respect to the current runtime object.
         *
         * @return  the <code>Runtime</code> object associated with the current
         *          Java application.
         */
        public static Runtime getRuntime() {
            return currentRuntime;
        }
    
        /** Don't let anyone else instantiate this class */
        private Runtime() {}
    }
    好记性不如烂笔头,提升自己:http://www.urlort.cn/1DjfQb github地址:https://github.com/997480972
  • 相关阅读:
    SQLHELPER C#
    SQL存储过程实例
    gridview css 样式及分页
    触发器
    MSsql存储过程
    解决在pc上用apk downloader插件下载谷歌play商店android应用出现的ssl错误
    VBScript输出显示双引号
    asp课堂更改读写权限值的实现
    1421. Credit Operations 夜
    sdut 1944 Flash Mob 夜
  • 原文地址:https://www.cnblogs.com/liuyong1993/p/9836655.html
Copyright © 2011-2022 走看看