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 就是经典的单例模式(饿汉式)

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

    收住自己的心 一步一个脚印 做好自己的事
  • 相关阅读:
    滚动条美化插件 nicescroll
    百度地图api
    Echarts的重点
    3月20号课堂随笔
    循环for语句
    有关一些CSS的基本内容
    HTML基本标签和一些注释的问题
    2018年3月17号的随堂笔记
    03.15补习
    for 的相关用法
  • 原文地址:https://www.cnblogs.com/GodMode/p/13764939.html
Copyright © 2011-2022 走看看