Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ThreadSafeSingleton {
- private static volatile ThreadSafeSingleton singleton;
- private ThreadSafeSingleton() {} //private constructor
- private synchronized static ThreadSafeSingleton getInstance() { // we synchronize the method
- if (null == singleton) { // if no instance is created we create one
- singleton = new ThreadSafeSingleton();
- }
- return singleton;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement