Singleton in JDK analysis application's source code
Singleton analysis application in the source JDK
1)
We
JDK
in,
java.lang.Runtime
is a classic example of the single-mode
( starving style )
2)
code analysis
+ the Debug
source
+
Code Description
Singleton notes and detailed instructions
1) Singleton pattern to ensure that the memory system there is only one object class , saving system resources, to create some objects that require frequent destruction, single-use-case model can improve system performance
2) When a single embodiment want to instantiate class, you must remember to use the corresponding method for acquiring an object , instead of using the new
3) Scene Singleton used : require frequent creation and destruction of objects , consuming too much or consume too many resources (that is, when you create an object: heavyweight objects), but frequently used objects , tools Objects , frequent access to the database files or objects (such as the data source, session factories, etc.)