Design Pattern: Singleton
Contents
Singleton pattern ensures that there is only one instance of a class is created in JVM. It is used to provide global point of access to the object.
###Implementation example: Lazy initialization
|
|
###Implementation example: Eager initialization
|
|
In the second implementation, the Singleton instance is instantiated when the class is loaded, while in the first implementation, the instance is not instantiated until it is acturally needed, but the first implementation is not thread safe.