Question d’entretien chez Zensar Technologies

Explain the creation of a thread-safe singleton in Java using double-checks locking

Réponse à la question d'entretien

Utilisateur anonyme

26 sept. 2018

Singleton is created with double checked locking as before Java 5 acts as an broker and it’s been possible to have multiple instances of Singleton when multiple threads creates an instance of Singleton at the same time. Java 5 made it easy to create thread-safe Singleton using Enum. Using a volatile variable is essential for the same.