• 单例模式


    单例模式: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
  • 相关阅读:
    test
    4css
    3css
    2css
    5html
    1css
    4html
    3html
    2html
    1.3 tensorflow2.0 常用函数
  • 原文地址:https://www.cnblogs.com/liuyong1993/p/9836655.html
Copyright © 2020-2023  润新知