zoukankan      html  css  js  c++  java
  • 原子类 Atomic

      

    @Test
    public void testAtomicBoolean() {
    AtomicBoolean atomicBoolean = new AtomicBoolean();
    boolean b = atomicBoolean.get();
    System.out.println("默认值:" + b);
    atomicBoolean.set(true);
    System.out.println(atomicBoolean.get());
    }

    @Test
    public void testAtomic() throws NoSuchFieldException {
    System.out.println(AtomicInteger.class.getDeclaredField("value"));
    AtomicInteger atomicInteger = new AtomicInteger();
    int i = atomicInteger.get();
    System.out.println("defaultValue:" + i);
    //当前值 + 1
    atomicInteger.getAndIncrement();
    System.out.println("getAndIncrement:" + atomicInteger.get());
    //指定增加数量 + n
    atomicInteger.getAndAdd(4);
    System.out.println("getAndAdd:" + atomicInteger.get());
    //当前值 - 1
    atomicInteger.getAndDecrement();
    System.out.println("getAndDecrement:" + atomicInteger.get());
    //当前值 + 1 并返回结果
    System.out.println("incrementAndGet:" + atomicInteger.incrementAndGet());
    //当前值 - 1 并返回结果
    System.out.println("decrementAndGet:" + atomicInteger.decrementAndGet());
    //当前值 + n 并返回结果
    System.out.println("addAndGet:" + atomicInteger.addAndGet(5));

    System.out.println("doubleValue:" + atomicInteger.doubleValue());
    System.out.println("longValue:" + atomicInteger.longValue());
    System.out.println("floatValue:" + atomicInteger.floatValue());
    System.out.println("byteValue:" + atomicInteger.byteValue());
    System.out.println("shortValue:" + atomicInteger.shortValue());
    System.out.println("toString:" + atomicInteger.toString());
    }
  • 相关阅读:
    【三中校内训练】怎样更有力气
    【四校联考】立方体
    【四校联考】点
    第11章 卷积神经网络(CNNs)
    第10章神经网络基础
    在jupyter中配置python3
    第9章 优化方法和归一化
    第8章 参数化学习(parameterized learning)
    第7章 你的第一个分类器
    第6章 配置开发环境
  • 原文地址:https://www.cnblogs.com/ming-blogs/p/11906936.html
Copyright © 2011-2022 走看看