zoukankan      html  css  js  c++  java
  • 源码中的设计模式-单例模式

    jdk源码

    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() {}
    
    ...
    }
    

      JDK 中,java.lang.Runtime 就是经典的单例模式(饿汉式)

    单例模式保证了系统内存中该类只存在一个对象,节省了系统资源,对一些需要频繁创建销毁/耗时/耗费资源的对象(比如工具类、频繁访问数据库或文件的对象),单例模式可以提高系统性能。

    收住自己的心 一步一个脚印 做好自己的事
  • 相关阅读:
    2020.7.11
    2020.7.13
    2020.7.9
    2020.7.10
    Java入门——day13
    Java入门——day12
    Java入门——day11
    虚拟交换机
    KVM虚拟化 ProxmoxVE
    【路径】python环境错误调试【执行路径】【操作系统,版本】
  • 原文地址:https://www.cnblogs.com/GodMode/p/13764939.html
Copyright © 2011-2022 走看看