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
  • 相关阅读:
    awk 正则匹配指定字段次数统计
    base64图片内容下载转为图片保存
    基于keras的fasttext短文本分类
    ubuntu 更换为mac主题
    ubuntu crontab python 定时任务备记
    ubuntu14.04 安装jdk1.8及以上
    fastext 中文文本分类
    django 多线程下载图片
    中文词向量训练
    mongodb 安装使用备记
  • 原文地址:https://www.cnblogs.com/liuyong1993/p/9836655.html
Copyright © 2011-2022 走看看