代码:
import java.util.concurrent.atomic.AtomicInteger;
class Foo {
private final AtomicInteger atomic = new AtomicInteger(0);
public Foo() {
}
public void first(Runnable printFirst) throws InterruptedException {
// printFirst.run() outputs "first". Do not change or remove this line.
printFirst.run();
//+1
atomic.incrementAndGet();
}
public void second(Runnable printSecond) throws InterruptedException {
//没执行过first则一直不跑second
while (atomic.get() != 1) {
}
// printSecond.run() outputs "second". Do not change or remove this line.
printSecond.run();
//+1
atomic.incrementAndGet();
}
public void third(Runnable printThird) throws InterruptedException {
while (atomic.get() != 2) {
}
// printThird.run() outputs "third". Do not change or remove this line.
printThird.run();
}
}
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- igbc.cn 版权所有 湘ICP备2023023988号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务