Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. public class Singleton {
  2.         private static volatile Singleton instance;
  3.  
  4.         private Singleton() {}
  5.    
  6.         public static Singleton getInstance() {
  7.         Singleton localInstance = instance;
  8.         if (localInstance == null) {
  9.             synchronized (Singleton.class) {
  10.                 localInstance = instance;
  11.                 if (localInstance == null) {
  12.                     instance = localInstance = new Singleton();
  13.                 }
  14.             }
  15.         }
  16.         return localInstance;
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement