Advertisement
999ms

Untitled

Aug 25th, 2020 (edited)
1,392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. class Singleton {
  2.     private class A {
  3.         final int value;
  4.     }
  5.    
  6.     private static A state = null;
  7.     private static boolean exists = true;
  8.     private Mutex mutex;
  9.    
  10.     Signleton() {}
  11.    
  12.     public A getState() {
  13.         if (exists) {
  14.             return state;
  15.         }
  16.        
  17.         mutex.lock();
  18.         try {
  19.             if (state == null) {
  20.                 state = new A();
  21.                 if (state != null) {
  22.                     exists = true;
  23.                 }
  24.             }
  25.         } finally {
  26.             mutex.unlock();
  27.         }
  28.        
  29.         return state;
  30.     }
  31. }
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement