AtomicReference類的setPlain()方法用於使用設置的內存語義來設置此AtomicReference對象的值,就像將該變量聲明為非易失性且非最終變量一樣。
用法:
public final void setPlain(V newValue)
參數:此方法接受newValue,它是要設置的新值。
返回值:此方法不返回任何內容。
以下示例程序旨在說明setPlain()方法:
程序1:
// Java program to demonstrate
// AtomicReference.setPlain() method
import java.util.concurrent.atomic.AtomicReference;
public class GFG {
public static void main(String[] args)
{
// create an atomic reference object.
AtomicReference<Long> ref
= new AtomicReference<Long>();
// set some value using setPlain method
ref.setPlain(999945678979L);
// print value
System.out.println("value = " + ref.get());
}
}
輸出:
程序2:
// Java program to demonstrate
// AtomicReference.setPlain() 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 using setPlain()
ref.setPlain("String Buffer");
// print value
System.out.println("Class = " + ref.get());
}
}
輸出:
相關用法
- Java AtomicReferenceArray setPlain()用法及代碼示例
- Java AtomicReference set()用法及代碼示例
- Java AtomicReference get()用法及代碼示例
- Java AtomicReference compareAndSet()用法及代碼示例
- Java AtomicReference getAcquire()用法及代碼示例
- Java AtomicReference getAndAccumulate()用法及代碼示例
- Java AtomicReference getAndSet()用法及代碼示例
- Java AtomicReference setRelease()用法及代碼示例
- Java AtomicReference updateAndGet()用法及代碼示例
- Java AtomicReference getAndUpdate()用法及代碼示例
- Java AtomicReference compareAndExchange()用法及代碼示例
- Java AtomicReference getPlain()用法及代碼示例
- Java AtomicReference accumulateAndGet()用法及代碼示例
- Java AtomicReference getOpaque()用法及代碼示例
- Java AtomicReference setOpaque()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 AtomicReference setPlain() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。