1 Star 0 Fork 0

firewaycoding/think_in_java

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
AtomicIntegerTest.java 972 Bytes
一键复制 编辑 原始数据 按行查看 历史
firewaycoding 提交于 2019-03-14 07:29 +08:00 . 本次应用修改:调整目录架构
/**
* 原子类
* 2019年 01月 03日 星期四
*
* @author fireway
*/
package concurrency;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
public class AtomicIntegerTest implements Runnable {
private AtomicInteger mI = new AtomicInteger(0);
@Override
public void run() {
while (true) {
evenIncrement();
}
}
private void evenIncrement() {
mI.addAndGet(2);
}
public int getValue() {
return mI.get();
}
public static void main(String[] args) {
ExecutorService exec = Executors.newCachedThreadPool();
AtomicIntegerTest ait = new AtomicIntegerTest();
exec.execute(ait);
while (true) {
int value = ait.getValue();
if (value % 2 != 0) {
System.out.println(value);
System.exit(0);
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/firewaycoding/think_in_java.git
git@gitee.com:firewaycoding/think_in_java.git
firewaycoding
think_in_java
think_in_java
master

搜索帮助