CountDownLatch latch = new CountDownLatch(1);
Thread one = new Thread(new Runnable() {
@Override
public void run() {
a = 1;
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
x = b;
}
});
Thread two = new Thread(new Runnable() {
@Override
public void run() {
b = 1;
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
y = a;
}
});
two.start();
one.start();
latch.countDown();
one.join();
two.join();
老师我改了latch.await();写的位置,这样不就意味着,a和b都已经被赋值1了然后被卡住,为什么还会出现1,0的情况