AtomicReference getPlain() method in Java with Examples
The getPlain() method of a AtomicReference class is used to return the current value of AtomicReference object, with memory semantics of reading as if the variable was declared non-volatile.
Syntax:
public final V getPlain()
Parameters: This method accepts nothing.
Return value: This method returns the value of AtomicReference.
Below programs illustrate the getPlain() method:
Program 1:
import java.util.concurrent.atomic.AtomicReference;
public class GFG {
public static void main(String[] args)
{
AtomicReference<Integer> ref
= new AtomicReference<Integer>();
ref.set( 564324 );
int value = ref.getPlain();
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 value" );
String value = ref.getPlain();
System.out.println( "Value = " + value);
}
}
|
Output:
References: https://docs.oracle.com/javase/10/docs/api/java/util/concurrent/atomic/AtomicReference.html#getPlain(V)
Last Updated :
27 Dec, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...