Guest User

Untitled

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