Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ThreadSafeSingletonWithDoubleCheckedLocking {
- private static ThreadSafeSingletonWithDoubleCheckedLocking threadSafeSingleton;
- /**
- * private constructor so that other classes can't
- * instantiate it through constructor
- * any instantiation while creating new singleton instance should come here
- */
- private ThreadSafeSingletonWithDoubleLocking() {}
- public static synchronized ThreadSafeSingletonWithDoubleCheckedLocking getInstance() {
- if(threadSafeSingleton == null) {
- synchronized(ThreadSafeSingletonWithDoubleCheckedLocking.class) {
- threadSafeSingleton = new ThreadSafeSingletonWithDoubleCheckedLocking();
- }
- }
- return threadSafeSingleton;
- }
- }
Add Comment
Please, Sign In to add comment