Skip to content
Related Articles

Related Articles

Improve Article
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:






// Java program to demonstrate
// AtomicReference.getOpaque() method
import java.util.concurrent.atomic.AtomicReference;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create an atomic reference object.
        AtomicReference<Double> ref
            = new AtomicReference<Double>();
  
        // set some value
        ref.set(564324.2345);
  
        // get value using getOpaque()
        double value = ref.getOpaque();
  
        // print
        System.out.println("Value = " + value);
    }
}
Output:

Program 2:




// Java program to demonstrate
// AtomicReference.getOpaque() method
import java.util.concurrent.atomic.AtomicReference;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create an atomic reference object.
        AtomicReference<String> ref
            = new AtomicReference<String>();
  
        // set some value
        ref.set("AtomicReference old value");
  
        // get value getOpaque()
        String value = ref.getOpaque();
  
        // print
        System.out.println("Value = " + value);
    }
}
Output:

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

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :