public class Test {
public static void main(String[] args) {
Runnable runnable = new Runnable() {
private int count = 0;
@Override
public void run() {
try {
for (int i = 0; i < 10; i++) {
System.out.println(count++);
Thread.sleep(100);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
Thread a = new Thread(runnable);
a.start();
Thread b = new Thread(runnable);
b.start();
}
}
=========================console========================
0
1
2
3
4
5
6
6
8
7
9
9
10
10
11
12
13
14
15
16
===================================================
println方法是使用synchronized修饰的同步方法,为什么还会出现这种数据count不同步的情况?