美文网首页
2018-10-30

2018-10-30

作者: 怎样会更好 | 来源:发表于2018-10-30 17:39 被阅读0次
    + View code
    /**
     * @author zhengbinMac
     */
    public class NoVisibility {
        private static boolean ready;
        private static int number;
        private static class ReaderThread extends Thread {
            @Override
            public void run() {
                while(!ready) {
                    Thread.yield();
                }
                System.out.println(number);
            }
        }
        public static void main(String[] args) {
            new ReaderThread().start();
            number = 42;
            ready = true;
        }
    }
    

    相关文章

      网友评论

          本文标题:2018-10-30

          本文链接:https://www.haomeiwen.com/subject/ibtntqtx.html