@@ -0,0 +1,777 @@
+package jdk.thread.volatiles;%0A%0A/**%0A * Created by whydk on 3/14/2017.%0A */%0Apublic class VolatileExample2 %7B%0A%0A    int a = 0;%0A    volatile boolean flag = false;%0A%0A    public void writer() %7B%0A%0A        a = 1; //1%0A%0A        flag = true; //2%0A    %7D%0A%0A    public void reader() %7B%0A        if (flag) %7B //3%0A%0A            int i = a; //4%0A            System.out.println(i);%0A//                        %E2%80%A6%E2%80%A6%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        VolatileExample2 volatileExample2 = new VolatileExample2();%0A        Thread flagThread = new Thread(() -%3E %7B%0A            volatileExample2.writer();%0A        %7D);%0A%0A        Thread readerThread = new Thread(() -%3E %7B%0A            volatileExample2.reader();%0A        %7D);%0A%0A        flagThread.start();%0A        readerThread.start();%0A    %7D%0A%7D%0A

add volatile test