AtomicIntegerFieldUpdater sample code
程序员文章站
2022-07-14 12:46:44
...
import java.util.concurrent.atomic.*;
class Container {
public volatile int no;
}
class Task extends Thread {
private AtomicIntegerFieldUpdater<Container> updater =
AtomicIntegerFieldUpdater.newUpdater(Container.class, "no");
private Container c;
public Task(Container c) {
this.c = c;
}
@Override
public void run() {
System.out.println(updater.getAndIncrement(c));
System.out.println(updater.getAndIncrement(c));
}
}
public class UpdaterUsage {
public static void main (String [] args) {
Container c = new Container();
Task t1 = new Task(c);
Task t2 = new Task(c);
t1.start();
t2.start();
}
}
上一篇: Ubuntu18.04使用GPG加密工具
下一篇: Gradle命令收集
推荐阅读
-
C#生成Code39条形码而非条形码字体的方法
-
解决Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-f8IeEI/MYSQL-python/
-
Entity Framework Code First属性映射约定
-
记录微信支付开发中的小经验(errcode = 40163; errmsg = "code been used")
-
利用Typings为Visual Studio Code实现智能提示功能
-
全新Visual Studio Code预览版0.10.10发布下载
-
Let's Code
-
ubuntu下VS code如何调试C++代码
-
详解VS Code使用之Vue工程配置format代码格式化
-
CKEditor 4.4.1 添加代码高亮显示插件功能教程【使用官方推荐Code Snippet插件】