Example usage for java.util.concurrent.atomic AtomicIntegerArray compareAndSet

List of usage examples for java.util.concurrent.atomic AtomicIntegerArray compareAndSet

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicIntegerArray compareAndSet.

Prototype

public final boolean compareAndSet(int i, int expectedValue, int newValue) 

Source Link

Document

Atomically sets the element at index i to newValue if the element's current value == expectedValue , with memory effects as specified by VarHandle#compareAndSet .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    AtomicIntegerArray atomicIntegerArray = new AtomicIntegerArray(new int[] { 0, 1, 2, 3 });

    atomicIntegerArray.compareAndSet(0, 10, 20);

    System.out.println(atomicIntegerArray.addAndGet(2, 10));
}