Java / Design Patterns
How do you implement a thread-safe Singleton in Java?
There are multiple ways to write thread-safe singleton in Java.
- using double checked locking,
- by using static Singleton instance initialized during class loading.
- using Java enum to create a thread-safe singleton class.
Using Java enum to create thread-safe singleton is the most simplest way.
More Related questions...