Sunday, December 14, 2025
HomeLanguagesJavaAtomicReference getAcquire() method in Java with Examples

AtomicReference getAcquire() method in Java with Examples

The getAcquire() method of a AtomicReference class is used to return the value of this AtomicReference object with memory ordering effects on getting variable is compatible with memory_order_acquire ordering.

Syntax: 

public final V getAcquire()

Parameters: This method accepts nothing.
Return value: This method returns the current value of this AtomicReference object with memory ordering effects.

Below programs illustrate the getAcquire() method:

Program 1:  

Java




// Java program to demonstrate
// AtomicReference.getAcquire() method
 
import java.util.concurrent.atomic.AtomicReference;
 
public class GFG {
    public static void main(String[] args)
    {
 
        // create an atomic reference object
        // which stores Integer.
        AtomicReference<Integer> ref
            = new AtomicReference<Integer>();
 
        // set some value
        ref.set(1632798372);
 
        // apply getAcquire() and print value
        int value = ref.getAcquire();
        System.out.println("value  = " + value);
    }
}


Output:

Program 2: 

Java




// Java program to demonstrate
// AtomicReference.getAcquire() method
import java.util.concurrent.atomic.AtomicReference;
 
public class GFG {
    public static void main(String[] args)
    {
 
        // create an atomic reference object
        // which stores String.
        AtomicReference<String> ref
            = new AtomicReference<String>();
 
        // set some value
        ref.set("WELCOME TO "
                + "GEEKS FOR GEEKS"
                + " LEARN AND APPLY");
 
        // apply getAcquire and print value
        String value = ref.getAcquire();
        System.out.println(value);
    }
}


Output:

Reference: https://docs.oracle.com/javase/10/docs/api/java/util/concurrent/atomic/AtomicReference.html#getAcquire()
 

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32448 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6817 POSTS0 COMMENTS
Nicole Veronica
11954 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12031 POSTS0 COMMENTS
Shaida Kate Naidoo
6953 POSTS0 COMMENTS
Ted Musemwa
7202 POSTS0 COMMENTS
Thapelo Manthata
6899 POSTS0 COMMENTS
Umr Jansen
6883 POSTS0 COMMENTS