Code example for AtomicReference

Methods: compareAndSet, get

0
 
    private FolderIcon() { 
    } 
     
    public static Image getOpenedIcon() { 
        if (OPENED_FOLDER_ICON.get() == null) {
            Image image = getSystemFolderImage(true);
            OPENED_FOLDER_ICON.compareAndSet(null,image);
        } 
        return OPENED_FOLDER_ICON.get();
    } 
     
    public static Image getClosedIcon() { 
        if (CLOSED_FOLDER_ICON.get() == null) {
            Image image = getSystemFolderImage(false);
            CLOSED_FOLDER_ICON.compareAndSet(null,image);
        } 
        return CLOSED_FOLDER_ICON.get();
    } 
     
    private static Image getSystemFolderImage(boolean isOpened) {