Detailed explanation of single example mode of Java design pattern [lazy and hungry]
This article describes the singleton pattern of Java design pattern. Share with you for your reference, as follows:
Singleton mode is to generate an object instance for external access.
Its application scenario is that when this class needs unified access to global real resources, otherwise it will cause confusion, it is necessary to design it as a singleton.
Lazy type is to check whether the object is created when using the object. If not, create it immediately. If it has been created, return the instance.
Hungry Chinese style, when loading this class, first create an object instance and wait for the call.
We can also guess the advantages and disadvantages of the two. Using the lazy style, the reaction speed must be slower than the hungry style.
However, if this object is not called, it saves CPU and memory resources.
The pattern is very simple. An example is given below.
test
For more Java related content, interested readers can view the special topics of this site: Java data structure and algorithm tutorial, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills