AtomicReferenceArray类的getAcquire()方法用于返回具有与memory_order_acquire排序兼容的内存排序效果的此AtomicReferenceArray对象的索引i处的元素的值。
用法:
public final E getAcquire(int i)
参数:此方法接受索引i以获取值。
返回值:此方法返回索引i处的当前值。
以下示例程序旨在说明getAcquire()方法:
程序1:
// Java program to demonstrate
// AtomicReferenceArray.getAcquire() method
import java.util.concurrent.atomic.AtomicReferenceArray;
public class GFG {
public static void main(String[] args)
{
// create an atomic reference array
// object which stores Integer.
AtomicReferenceArray<Integer> array
= new AtomicReferenceArray<Integer>(5);
// set some value in array
array.set(0, 1213);
array.set(1, 1344);
array.set(2, 1453);
array.set(3, 1452);
// get and print the value
// using getAcquire method
for (int i = 0; i < 4; i++) {
int value = array.getAcquire(i);
System.out.println("value at "
+ i + " = " + value);
}
}
}
输出:
程序2:
// Java program to demonstrate
// AtomicReferenceArray.getAcquire() method
import java.util.concurrent.atomic.AtomicReferenceArray;
public class GFG {
public static void main(String[] args)
{
// create an atomic reference array object
// which stores String.
AtomicReferenceArray<String> array
= new AtomicReferenceArray<String>(5);
// set some value in array
array.set(0, "GEEKS");
array.set(1, "FOR");
array.set(2, "GEEKS");
// get and print the value using get method
for (int i = 0; i < 2; i++) {
String value = array.getAcquire(i);
System.out.println("value at "
+ i + " = " + value);
}
}
}
输出:
相关用法
- Java AtomicReference getAcquire()用法及代码示例
- Java AtomicReferenceArray get()用法及代码示例
- Java AtomicReferenceArray set()用法及代码示例
- Java AtomicReferenceArray updateAndGet()用法及代码示例
- Java AtomicReferenceArray lazySet()用法及代码示例
- Java AtomicReferenceArray getAndUpdate()用法及代码示例
- Java AtomicReferenceArray getPlain()用法及代码示例
- Java AtomicReferenceArray getOpaque()用法及代码示例
- Java AtomicReferenceArray toString()用法及代码示例
- Java AtomicReferenceArray length()用法及代码示例
- Java AtomicReferenceArray getAndAccumulate()用法及代码示例
- Java AtomicReferenceArray getAndSet()用法及代码示例
- Java AtomicReferenceArray compareAndSet()用法及代码示例
- Java AtomicReferenceArray accumulateAndGet()用法及代码示例
- Java AtomicReferenceArray compareAndExchangeRelease()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 AtomicReferenceArray getAcquire() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。