0
点赞
收藏
分享

微信扫一扫

Don't Do this :Sharing Variables without Synchronization.

七公子706 2022-07-27 阅读 68


Sharing Variables without Synchronization.Don't Do this.

public class NoVisibility {

private static boolean ready; private static int number; private static class ReaderThread extends Thread { public void run() { while (!ready) Thread.yield(); System.out.println(number); } } public static void main(String[] args) { new ReaderThread().start(); number = 42; ready = true; }}

举报

相关推荐

0 条评论