當前位置: 首頁>>代碼示例>>Java>>正文


Java AtomicReferenceFieldUpdater.get方法代碼示例

本文整理匯總了Java中java.util.concurrent.atomic.AtomicReferenceFieldUpdater.get方法的典型用法代碼示例。如果您正苦於以下問題:Java AtomicReferenceFieldUpdater.get方法的具體用法?Java AtomicReferenceFieldUpdater.get怎麽用?Java AtomicReferenceFieldUpdater.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.atomic.AtomicReferenceFieldUpdater的用法示例。


在下文中一共展示了AtomicReferenceFieldUpdater.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: set

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
/**
 * Atomically push the field to a {@link Disposable} and dispose the old content.
 *
 * @param updater the target field updater
 * @param holder the target instance holding the field
 * @param newValue the new Disposable to push
 * @return true if successful, false if the field contains the {@link #DISPOSED} instance.
 */
static <T> boolean set(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder, @Nullable Disposable newValue) {
	for (;;) {
		Disposable current = updater.get(holder);
		if (current == DISPOSED) {
			if (newValue != null) {
				newValue.dispose();
			}
			return false;
		}
		if (updater.compareAndSet(holder, current, newValue)) {
			if (current != null) {
				current.dispose();
			}
			return true;
		}
	}
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:26,代碼來源:Disposables.java

示例2: set

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
/**
 * Atomically push the field to a {@link Disposable} and dispose the old content.
 *
 * @param updater the target field updater
 * @param holder the target instance holding the field
 * @param newValue the new Disposable to push
 * @return true if successful, false if the field contains the {@link #DISPOSED} instance.
 */
public static <T> boolean set(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder, @Nullable Disposable newValue) {
	for (;;) {
		Disposable current = updater.get(holder);
		if (current == DISPOSED) {
			if (newValue != null) {
				newValue.dispose();
			}
			return false;
		}
		if (updater.compareAndSet(holder, current, newValue)) {
			if (current != null) {
				current.dispose();
			}
			return true;
		}
	}
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:26,代碼來源:OperatorDisposables.java

示例3: set

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
/**
 * A generic utility to atomically replace a subscription or cancel the replacement
 * if current subscription is marked as cancelled (as in {@link #cancelledSubscription()})
 * or was concurrently updated before.
 * <p>
 * The replaced subscription is itself cancelled.
 *
 * @param field The Atomic container
 * @param instance the instance reference
 * @param s the subscription
 * @param <F> the instance type
 *
 * @return true if replaced
 */
public static <F> boolean set(AtomicReferenceFieldUpdater<F, Subscription> field,
		F instance,
		Subscription s) {
	for (; ; ) {
		Subscription a = field.get(instance);
		if (a == CancelledSubscription.INSTANCE) {
			s.cancel();
			return false;
		}
		if (field.compareAndSet(instance, a, s)) {
			if (a != null) {
				a.cancel();
			}
			return true;
		}
	}
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:32,代碼來源:Operators.java

示例4: removeSequence

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
/**
 * 原子移除某個指定的sequence
 *
 * @param holder 原子更新的域所屬的類對象
 * @param sequenceUpdater 原子更新的域對象
 * @param sequence 要移除的sequence
 * @param <T>
 * @return
 */
public static <T> boolean removeSequence(
        final T holder,
        final AtomicReferenceFieldUpdater<T, Sequence[]> sequenceUpdater,
        final Sequence sequence)
{
    int numToRemove;
    Sequence[] oldSequences;
    Sequence[] newSequences;

    do
    {
        oldSequences = sequenceUpdater.get(holder);

        numToRemove = countMatching(oldSequences, sequence);

        if (0 == numToRemove)
        {
            break;
        }

        final int oldSize = oldSequences.length;
        newSequences = new Sequence[oldSize - numToRemove];

        for (int i = 0, pos = 0; i < oldSize; i++)
        {
            final Sequence testSequence = oldSequences[i];
            if (sequence != testSequence)
            {
                newSequences[pos++] = testSequence;
            }
        }
    }
    while (!sequenceUpdater.compareAndSet(holder, oldSequences, newSequences));

    return numToRemove != 0;
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:46,代碼來源:SequenceGroups.java

示例5: testFieldUpdaters_ClassCastException

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
/**
 * Object arguments for parameters of type T that are not
 * instances of the class passed to the newUpdater call will
 * result in a ClassCastException being thrown.
 */
public void testFieldUpdaters_ClassCastException() {
    // Use raw types to allow passing wrong object type, provoking CCE
    final AtomicLongFieldUpdater longUpdater = aLongFieldUpdater();
    final AtomicIntegerFieldUpdater intUpdater = anIntFieldUpdater();
    final AtomicReferenceFieldUpdater refUpdater = anIntegerFieldUpdater();
    final Object obj = new Object();
    for (Object x : new Object[]{ new Object(), null }) {
        Runnable[] throwingActions = {
            () -> longUpdater.get(x),
            () -> intUpdater.get(x),
            () -> refUpdater.get(x),

            () -> longUpdater.set(x, 17L),
            () -> intUpdater.set(x, 17),
            () -> refUpdater.set(x, (Integer) 17),

            () -> longUpdater.addAndGet(x, 17L),
            () -> intUpdater.addAndGet(x, 17),

            () -> longUpdater.getAndUpdate(x, y -> y),
            () -> intUpdater.getAndUpdate(x, y -> y),
            () -> refUpdater.getAndUpdate(x, y -> y),

            () -> longUpdater.compareAndSet(x, 17L, 42L),
            () -> intUpdater.compareAndSet(x, 17, 42),
            () -> refUpdater.compareAndSet(x, (Integer) 17, (Integer) 42),
        };
        assertThrows(ClassCastException.class, throwingActions);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:Atomic8Test.java

示例6: removeSequence

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
static <T> boolean removeSequence(
    final T holder,
    final AtomicReferenceFieldUpdater<T, Sequence[]> sequenceUpdater,
    final Sequence sequence)
{
    int numToRemove;
    Sequence[] oldSequences;
    Sequence[] newSequences;

    do
    {
        oldSequences = sequenceUpdater.get(holder);

        numToRemove = countMatching(oldSequences, sequence);

        if (0 == numToRemove)
        {
            break;
        }

        final int oldSize = oldSequences.length;
        newSequences = new Sequence[oldSize - numToRemove];

        for (int i = 0, pos = 0; i < oldSize; i++)
        {
            final Sequence testSequence = oldSequences[i];
            if (sequence != testSequence)
            {
                newSequences[pos++] = testSequence;
            }
        }
    }
    while (!sequenceUpdater.compareAndSet(holder, oldSequences, newSequences));

    return numToRemove != 0;
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:37,代碼來源:SequenceGroups.java

示例7: replace

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
/**
 * Atomically replace the {@link Disposable} in the field with the given new Disposable
 * but do not dispose the old one.
 *
 * @param updater the target field updater
 * @param holder the target instance holding the field
 * @param newValue the new Disposable to push, null allowed
 * @return true if the operation succeeded, false if the target field contained
 * the common {@link #DISPOSED} instance and the given disposable is not null but is disposed.
 */
static <T> boolean replace(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder, @Nullable Disposable newValue) {
	for (;;) {
		Disposable current = updater.get(holder);
		if (current == DISPOSED) {
			if (newValue != null) {
				newValue.dispose();
			}
			return false;
		}
		if (updater.compareAndSet(holder, current, newValue)) {
			return true;
		}
	}
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:25,代碼來源:Disposables.java

示例8: dispose

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
/**
 * Atomically dispose the {@link Disposable} in the field if not already disposed.
 *
 * @param updater the target field updater
 * @param holder the target instance holding the field
 * @return true if the {@link Disposable} held by the field was properly disposed
 */
static <T> boolean dispose(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder) {
	Disposable current = updater.get(holder);
	Disposable d = DISPOSED;
	if (current != d) {
		current = updater.getAndSet(holder, d);
		if (current != d) {
			if (current != null) {
				current.dispose();
			}
			return true;
		}
	}
	return false;
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:22,代碼來源:Disposables.java

示例9: setOnce

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
/**
 * Atomically push the field to the given non-null {@link Disposable} and return true,
 * or return false if the field is non-null.
 * If the target field contains the common {@link #DISPOSED} instance, the supplied disposable
 * is disposed. If the field contains other non-null {@link Disposable}, an {@link IllegalStateException}
 * is signalled to the {@code errorCallback}.
 *
 * @param updater the target field updater
 * @param holder the target instance holding the field
 * @param newValue the new Disposable to push, not null
 * @return true if the operation succeeded, false
 */
public static <T> boolean setOnce(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder, Disposable newValue,
		Consumer<RuntimeException> errorCallback) {
	Objects.requireNonNull(newValue, "newValue is null");
	if (!updater.compareAndSet(holder, null, newValue)) {
		newValue.dispose();
		if (updater.get(holder) != DISPOSED) {
			errorCallback.accept(new IllegalStateException("Disposable already pushed"));
		}
		return false;
	}
	return true;
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:25,代碼來源:OperatorDisposables.java

示例10: replace

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
/**
 * Atomically replace the {@link Disposable} in the field with the given new Disposable
 * but do not dispose the old one.
 *
 * @param updater the target field updater
 * @param holder the target instance holding the field
 * @param newValue the new Disposable to push, null allowed
 * @return true if the operation succeeded, false if the target field contained
 * the common {@link #DISPOSED} instance and the given disposable is not null but is disposed.
 */
public static <T> boolean replace(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder, @Nullable Disposable newValue) {
	for (;;) {
		Disposable current = updater.get(holder);
		if (current == DISPOSED) {
			if (newValue != null) {
				newValue.dispose();
			}
			return false;
		}
		if (updater.compareAndSet(holder, current, newValue)) {
			return true;
		}
	}
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:25,代碼來源:OperatorDisposables.java

示例11: dispose

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
/**
 * Atomically dispose the {@link Disposable} in the field if not already disposed.
 *
 * @param updater the target field updater
 * @param holder the target instance holding the field
 * @return true if the {@link Disposable} held by the field was properly disposed
 */
public static <T> boolean dispose(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder) {
	Disposable current = updater.get(holder);
	Disposable d = DISPOSED;
	if (current != d) {
		current = updater.getAndSet(holder, d);
		if (current != d) {
			if (current != null) {
				current.dispose();
			}
			return true;
		}
	}
	return false;
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:22,代碼來源:OperatorDisposables.java

示例12: trySet

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
/**
 * Atomically try to push the given {@link Disposable} on the field if it is null or
 * disposes it if the field contains {@link #DISPOSED}.
 *
 * @param updater the target field updater
 * @param holder the target instance holding the field
 * @param newValue the disposable to push
 * @return true if successful, false otherwise
 */
public static <T> boolean trySet(AtomicReferenceFieldUpdater<T, Disposable> updater, T holder, Disposable newValue) {
	if (!updater.compareAndSet(holder, null, newValue)) {
		if (updater.get(holder) == DISPOSED) {
			newValue.dispose();
		}
		return false;
	}
	return true;
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:19,代碼來源:OperatorDisposables.java

示例13: addSequence

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
static <T> void addSequence(final T holder,
		final AtomicReferenceFieldUpdater<T, Sequence[]> updater,
		final Sequence sequence) {

	Sequence[] updatedSequences;
	Sequence[] currentSequences;

	do {
		currentSequences = updater.get(holder);
		updatedSequences = copyOf(currentSequences, currentSequences.length + 1);

		updatedSequences[currentSequences.length] = sequence;
	}
	while (!updater.compareAndSet(holder, currentSequences, updatedSequences));
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:16,代碼來源:RingBuffer.java

示例14: removeSequence

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
static <T> boolean removeSequence(final T holder,
		final AtomicReferenceFieldUpdater<T, Sequence[]> sequenceUpdater,
		final Sequence sequence) {
	int numToRemove;
	Sequence[] oldSequences;
	Sequence[] newSequences;

	do {
		oldSequences = sequenceUpdater.get(holder);

		numToRemove = countMatching(oldSequences, sequence);

		if (0 == numToRemove) {
			break;
		}

		final int oldSize = oldSequences.length;
		newSequences = new Sequence[oldSize - numToRemove];

		for (int i = 0, pos = 0; i < oldSize; i++) {
			final Sequence testSequence = oldSequences[i];
			if (sequence != testSequence) {
				newSequences[pos++] = testSequence;
			}
		}
	}
	while (!sequenceUpdater.compareAndSet(holder, oldSequences, newSequences));

	return numToRemove != 0;
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:31,代碼來源:RingBuffer.java

示例15: replace

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; //導入方法依賴的package包/類
/**
 * A generic utility to atomically replace a subscription or cancel the replacement
 * if the current subscription is marked as already cancelled (as in
 * {@link #cancelledSubscription()}).
 *
 * @param field The Atomic container
 * @param instance the instance reference
 * @param s the subscription
 * @param <F> the instance type
 *
 * @return true if replaced
 */
public static <F> boolean replace(AtomicReferenceFieldUpdater<F, Subscription> field,
		F instance,
		Subscription s) {
	for (; ; ) {
		Subscription a = field.get(instance);
		if (a == CancelledSubscription.INSTANCE) {
			s.cancel();
			return false;
		}
		if (field.compareAndSet(instance, a, s)) {
			return true;
		}
	}
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:27,代碼來源:Operators.java


注:本文中的java.util.concurrent.atomic.AtomicReferenceFieldUpdater.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。