Guest User

Untitled

a guest
Apr 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. class ThreadSafeSingletonWithDoubleCheckedLocking {
  2. private static ThreadSafeSingletonWithDoubleCheckedLocking threadSafeSingleton;
  3. /**
  4. * private constructor so that other classes can't
  5. * instantiate it through constructor
  6. * any instantiation while creating new singleton instance should come here
  7. */
  8.  
  9. private ThreadSafeSingletonWithDoubleLocking() {}
  10.  
  11. public static synchronized ThreadSafeSingletonWithDoubleCheckedLocking getInstance() {
  12. if(threadSafeSingleton == null) {
  13. synchronized(ThreadSafeSingletonWithDoubleCheckedLocking.class) {
  14. threadSafeSingleton = new ThreadSafeSingletonWithDoubleCheckedLocking();
  15. }
  16. }
  17. return threadSafeSingleton;
  18. }
  19. }
Add Comment
Please, Sign In to add comment