Code example for AtomicReference

Methods: compareAndSetget

0
        this.initScriptCache = new AtomicReference<String>(null);
    } 
 
    @Override 
    public String getInitScript() throws IOException {
        String result = initScriptCache.get();
        if (result == null) {
            result = StringUtils.getResourceAsString(INIT_SCRIPT_PATH, Charset.forName("UTF-8"));
            initScriptCache.compareAndSet(null, result);
            result = initScriptCache.get();
        } 
        return result;
    } 
} 
Connect your IDE to all the code out there  Get Codota for Java