-
Notifications
You must be signed in to change notification settings - Fork 0
/
1114.java
35 lines (26 loc) · 942 Bytes
/
1114.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Foo {
private AtomicInteger first = new AtomicInteger(0);
private AtomicInteger second = 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();
first.incrementAndGet();
}
public void second(Runnable printSecond) throws InterruptedException {
while(first.get()!=1){
// 阻塞
}
// printSecond.run() outputs "second". Do not change or remove this line.
printSecond.run();
second.incrementAndGet();
}
public void third(Runnable printThird) throws InterruptedException {
while(second.get()!=1){
}
// printThird.run() outputs "third". Do not change or remove this line.
printThird.run();
second.incrementAndGet();
}
}