1 package com.test.a;
2
3 // LongArrayTest.java的源码
4 import java.util.concurrent.atomic.AtomicLongArray;
5
6 public class LongArrayTest {
7
8 public static void main(String[] args) {
9
10 // 新建AtomicLongArray对象
11 long[] arrLOng= new long[] { 10, 20, 30, 40, 50 };
12 AtomicLongArray ala = new AtomicLongArray(arrLong);
13
14 ala.set(0, 100);
15 for (int i = 0, len = ala.length(); i )
16 System.out.printf("get(%d) : %s\n", i, ala.get(i));
17
18 System.out.printf("%20s : %s\n", "getAndDecrement(0)", ala.getAndDecrement(0));
19 System.out.printf("%20s : %s\n", "decrementAndGet(1)", ala.decrementAndGet(1));
20 System.out.printf("%20s : %s\n", "getAndIncrement(2)", ala.getAndIncrement(2));
21 System.out.printf("%20s : %s\n", "incrementAndGet(3)", ala.incrementAndGet(3));
22
23 System.out.printf("%20s : %s\n", "addAndGet(100)", ala.addAndGet(0, 100));
24 System.out.printf("%20s : %s\n", "getAndAdd(100)", ala.getAndAdd(1, 100));
25
26 System.out.printf("%20s : %s\n", "compareAndSet()", ala.compareAndSet(2, 31, 1000));
27 System.out.printf("%20s : %s\n", "get(2)", ala.get(2));
28 }
29 }