Code example for AtomicReference

Methods: compareAndSet, get

0
/* 69 */   private final AtomicReference<T> reference = new AtomicReference();
/*    */  
/*    */   public T get() 
/*    */     throws ConcurrentException 
/*    */   { 
/* 81 */     Object result = this.reference.get();
/*    */  
/* 83 */     if (result == null) {
/* 84 */       result = initialize();
/* 85 */       if (!this.reference.compareAndSet(null, result))
/*    */       { 
/* 87 */         result = this.reference.get();
/*    */       } 
/*    */     } 
/*    */  
/* 91 */     return result;
/*    */   } 
/*    */  
/*    */   protected abstract T initialize() 
/*    */     throws ConcurrentException; 
/*    */ }