Singleton in JAVA

First the code

The code above is an example of a lazy singleton.

When we should use singleton?
A singleton should be used when managing access to a resource that is shared by the entire application, and it would be destructive to potentially have multiple instances of the same class. Making sure that access to shared resources thread-safe is one very good example of where this kind of pattern can be vital.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store