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

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

    收住自己的心 一步一个脚印 做好自己的事
  • 相关阅读:
    归并排序
    二分查找
    分治 递归 引用 求一个数组中的最大和最小元素
    插入排序
    Poj 2503
    SELinux 基础命令
    Zend Framework中的MVC架构
    phpfpm详解
    CentOS 6 minimal 安装
    php 5.3.3 中的phpfpm配置
  • 原文地址:https://www.cnblogs.com/GodMode/p/13764939.html
Copyright © 2011-2022 走看看