## volatile与synchronized的区别
package cn.qqjx.thread;
import java.util.List;
import java.util.ArrayList;
public class MyThread {
volatile int count = 0;
void m(){
for (int i = 0; i < 10000; i++) {
count++;
}
}
public static void main(String[] args) {
MyThread t = new MyThread();
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < 10 ; i++) {
threads.add(new Thread(t::m,"thread-"+i));
}
threads.forEach((o)->o.start());
threads.forEach((o)->{
try {
o.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
});
System.out.println("count:"+t.count);
}
}
count:49981