Java 8 AtomicReferenceFieldUpdater - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 AtomicReferenceFieldUpdater class.

This code example shows how to use the following methods:getAndSet, set
        checkAccess(this);
        if (applyLayout && appender != null) {
            final Formatter formatter = getFormatter();
            appender.setLayout(formatter == null ? null : new FormatterLayout(formatter));
        } 
        appenderUpdater.set(this, appender);
    } 
 
    @Override 
    public void setFormatter(final Formatter newFormatter) throws SecurityException {
        if (applyLayout) {
            final Appender appender = this.appender;
            if (appender != null) {
                appender.setLayout(new FormatterLayout(newFormatter));
            } 
        } 
        super.setFormatter(newFormatter);
    } 
 
    @Override 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:compareAndSet
    public volatile MainNode<K, V> prev = null;
 
    public abstract int cachedSize(Object ct);
 
    public boolean CAS_PREV(MainNode<K, V> oldval, MainNode<K, V> nval) {
	return updater.compareAndSet(this, oldval, nval);
    } 
 
    public void WRITE_PREV(MainNode<K, V> nval) {
	updater.set(this, nval);
    } 
 
    // do we need this? unclear in the javadocs... 
    // apparently not - volatile reads are supposed to be safe 
    // irregardless of whether there are concurrent ARFU updates 
    @Deprecated @SuppressWarnings("unchecked") 
    public MainNode<K, V> READ_PREV() { 
	return updater.get(this);
    } 
 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:compareAndSet
            } 
        } else { 
            newMap = new FastCopyHashMap<K, V>(snapshot);
            newMap.put(key, value);
        } 
        if (updater.compareAndSet(instance, snapshot, newMap)) {
            return null; 
        } else { 
            return value;
        } 
    } 
 
    public V putIfAbsent(C instance, K key, V value) {
        if (key == null) {
            throw MESSAGES.nullVar("key"); 
        } 
        for (;;) { 
            final Map<K, V> oldMap = updater.get(instance);
            final Map<K, V> newMap;
            final int oldSize = oldMap.size();
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:compareAndSet
            } 
        } else { 
            newMap = new FastCopyHashMap<K, V>(snapshot);
            newMap.put(key, value);
        } 
        if (updater.compareAndSet(instance, snapshot, newMap)) {
            return null; 
        } else { 
            return value;
        } 
    } 
 
    public V putIfAbsent(C instance, K key, V value) {
        if (key == null) {
            throw MESSAGES.nullVar("key"); 
        } 
        for (;;) { 
            final Map<K, V> oldMap = updater.get(instance);
            final Map<K, V> newMap;
            final int oldSize = oldMap.size();
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getAndSet
    } 
 
    @SuppressWarnings("unchecked") 
    protected final MpscLinkedQueueNode<E> getAndSetTailRef(MpscLinkedQueueNode<E> tailRef) {
        // LOCK XCHG in JDK8, a CAS loop in JDK 7/6 
        return (MpscLinkedQueueNode<E>) UPDATER.getAndSet(this, tailRef);
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:lazySet
    protected final void setHeadRef(MpscLinkedQueueNode<E> headRef) {
        this.headRef = headRef;
    } 
 
    protected final void lazySetHeadRef(MpscLinkedQueueNode<E> headRef) {
        UPDATER.lazySet(this, headRef);
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:lazySet
    } 
 
    final void setNext(final MpscLinkedQueueNode<T> newNext) {
        // Similar to 'next = newNext', but slightly faster (storestore vs loadstore) 
        // See: http://robsjava.blogspot.com/2013/06/a-faster-volatile.html 
        nextUpdater.lazySet(this, newNext);
    } 
 
    public abstract T value(); 
 
    /** 
     * Sets the element this node contains to {@code null} so that the node can be used as a tombstone. 
     */ 
    protected T clearMaybe() { 
        return value(); 
    } 
 
    /** 
     * Unlink to allow GC'ed 
     */ 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:compareAndSet
            nextUpdater =
            AtomicReferenceFieldUpdater.newUpdater
            (Node.class, Node.class, "next"); 
 
        boolean casNext(Node<E> cmp, Node<E> val) {
            return nextUpdater.compareAndSet(this, cmp, val);
        } 
                                                                    
    }                                                                  
 
    @SuppressWarnings("rawtypes") 
	private static final 
	    AtomicReferenceFieldUpdater<ConcNodeCachingLinkedQueue, Node>
	    tailUpdater =
	    AtomicReferenceFieldUpdater.newUpdater
	    (ConcNodeCachingLinkedQueue.class, Node.class, "tail"); 
	@SuppressWarnings("rawtypes") 
	private static final 
	    AtomicReferenceFieldUpdater<ConcNodeCachingLinkedQueue, Node>
	    headUpdater =
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:compareAndSet
                int nsz = pos * 2;
                if (nsz > marklimit)
                    nsz = marklimit;
                byte nbuf[] = new byte[nsz];
                System.arraycopy(buffer, 0, nbuf, 0, pos);
                if (!bufUpdater.compareAndSet(this, buffer, nbuf))
                { 
                    // Can't replace buf if there was an async close. 
                    // Note: This would need to be changed if fill() 
                    // is ever made accessible to multiple threads. 
                    // But for now, the only way CAS can fail is via close. 
                    // assert buf == null; 
                    throw new IOException("Stream closed");
                } 
                buffer = nbuf;
            } 
        count = pos;
        int n = getInIfOpen().read(buffer, pos, buffer.length - pos);
        if (n > 0)
            count = n + pos;
3
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:compareAndSet
            AtomicReferenceFieldUpdater.newUpdater(HandoverQueue.class, Node.class, "tail");
    private static final AtomicReferenceFieldUpdater<HandoverQueue, Node> headUpdater =
            AtomicReferenceFieldUpdater.newUpdater(HandoverQueue.class, Node.class, "head");
 
    private boolean casTail(Node<E> cmp, Node<E> val) {
        return tailUpdater.compareAndSet(this, cmp, val);
    } 
 
    private boolean casHead(Node<E> cmp, Node<E> val) {
        return headUpdater.compareAndSet(this, cmp, val);
    } 
 
    private volatile Node<E> head = new Node<E>(null, null);
 
    private volatile Node<E> tail = head;
 
    public boolean offer(E e) {
        if (e == null) throw new NullPointerException();
        Node<E> n = new Node<E>(e, null);
        while (true) { 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 AtomicReferenceFieldUpdater Methods: