AtomicReference getOpaque() method in Java with Examples
Last Updated :
27 Dec, 2019
The getOpaque() method of a AtomicReference class is used to return the current value of AtomicReference object, with memory effects as specified by VarHandle.getOpaque(java.lang.Object…). This VarHandle.getOpaque(java.lang.Object…) method handles operation with no assurance of memory ordering effects with respect to other threads.
Syntax:
public final V getOpaque()
Parameters: This method accepts nothing.
Return value: This method returns the value of AtomicReference.
Below programs illustrate the getOpaque() method:
Program 1:
import java.util.concurrent.atomic.AtomicReference;
public class GFG {
public static void main(String[] args)
{
AtomicReference<Double> ref
= new AtomicReference<Double>();
ref.set( 564324.2345 );
double value = ref.getOpaque();
System.out.println( "Value = " + value);
}
}
|
Output:
Program 2:
import java.util.concurrent.atomic.AtomicReference;
public class GFG {
public static void main(String[] args)
{
AtomicReference<String> ref
= new AtomicReference<String>();
ref.set( "AtomicReference old value" );
String value = ref.getOpaque();
System.out.println( "Value = " + value);
}
}
|
Output:
References: https://docs.oracle.com/javase/10/docs/api/java/util/concurrent/atomic/AtomicReference.html#getOpaque()
Share your thoughts in the comments
Please Login to comment...