AtomicReferenceArray getAcquire() method in Java with Examples

The getAcquire() method of a AtomicReferenceArray class is used to return the value of the element at index i for this AtomicReferenceArray object with memory ordering effects compatible with memory_order_acquire ordering.Â
Syntax:
public final E getAcquire(int i)
Parameters: This method accepts the index i to get the value.Â
Return value: This method returns current value at index I.Â
Below programs illustrate the getAcquire() method:Â
Program 1:Â
Java
// Java program to demonstrate// AtomicReferenceArray.getAcquire() methodÂ
import java.util.concurrent.atomic.AtomicReferenceArray;Â
public class GFG {Â Â Â Â public static void main(String[] args)Â Â Â Â {Â
        // create an atomic reference array        // object which stores Integer.        AtomicReferenceArray<Integer> array            = new AtomicReferenceArray<Integer>(5);Â
        // set some value in array        array.set(0, 1213);        array.set(1, 1344);        array.set(2, 1453);        array.set(3, 1452);Â
        // get and print the value        // using getAcquire method        for (int i = 0; i < 4; i++) {Â
            int value = array.getAcquire(i);            System.out.println("value at "                               + i + " = " + value);        }    }} |
Output: 

Program 2:Â
Java
// Java program to demonstrate// AtomicReferenceArray.getAcquire() methodÂ
import java.util.concurrent.atomic.AtomicReferenceArray;Â
public class GFG {Â Â Â Â public static void main(String[] args)Â Â Â Â {Â
        // create an atomic reference array object        // which stores String.        AtomicReferenceArray<String> array            = new AtomicReferenceArray<String>(5);Â
        // set some value in array        array.set(0, "GEEKS");        array.set(1, "FOR");        array.set(2, "GEEKS");Â
        // get and print the value using getAcquire method        for (int i = 0; i < 2; i++) {Â
            String value = array.getAcquire(i);            System.out.println("value at "                               + i + " = " + value);        }    }} |
Output: 




