Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. public class ThreadSafeSingleton {
  2.  
  3. private static volatile ThreadSafeSingleton singleton;
  4.  
  5. private ThreadSafeSingleton() {} //private constructor
  6.  
  7. private synchronized static ThreadSafeSingleton getInstance() { // we synchronize the method
  8.  
  9. if (null == singleton) { // if no instance is created we create one
  10. singleton = new ThreadSafeSingleton();
  11. }
  12.  
  13. return singleton;
  14. }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement