AtomicReference getAcquire() method in Java with Examples
Last Updated :
23 Apr, 2023
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
import java.util.concurrent.atomic.AtomicReference;
public class GFG {
public static void main(String[] args)
{
AtomicReference<Integer> ref
= new AtomicReference<Integer>();
ref.set( 1632798372 );
int value = ref.getAcquire();
System.out.println( "value = " + value);
}
}
|
Output:
Program 2:
Java
import java.util.concurrent.atomic.AtomicReference;
public class GFG {
public static void main(String[] args)
{
AtomicReference<String> ref
= new AtomicReference<String>();
ref.set( "WELCOME TO "
+ "GEEKS FOR GEEKS"
+ " LEARN AND APPLY" );
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()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...