62,614
社区成员
发帖
与我相关
我的任务
分享
public class NoVisibility {
private static boolean ready;
private static int number;
private static class ReadThread extends Thread {
public void run() {
while (!ready) {
Thread.yield();
}
System.out.println(number);
}
}
public static void main(String[] args) throws InterruptedException {
new ReadThread().start();
number = 42;
ready = true;
System.out.println("set ready:" + ready);
}
}