Code example for AtomicReference

Methods: compareAndSetget

0
     * Method get. 
     *  
     * @return T 
     */ 
    public T get() { 
        T ret = instance.get();
        if (ret == null) {
            try { 
                ret = clazz.newInstance();
                if (!instance.compareAndSet(null, ret))
                    ret = instance.get();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            } 
        } 
        return ret;
    } 
} 
Contextual code suggestions in your IDE  Get Codota for Java