單例模式在JDK應用的源碼分析
單例模式在jdk中的源碼分析
-
在我們JDK中,java.lang.Runtime就是經典的單例模式(惡漢式)
-
代碼分析+Debug源碼+代碼說明
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://victorfengming.gitee.io/design_pattern/