使用了synchronized,为啥还有线程安全问题?
public class Run9 {
static int count = 5;
static class MyThread extends Thread{
public MyThread(String name) {
this.setName(name);
}
@Override
synchronized public void run() {
super.run();
{
count --;
System.out.println("由 " + this.getName() + "计算,count = " + count);
}
}
}
public static void main(String[] args) {
MyThread[] arr = new MyThread[5];
String[] name = {"A","B","C","D","E"};
for (int i = 0; i < 5; i++) {
arr[i] = new MyThread(name[i]);
}
for (int i = 0; i < 5; i++) {
arr[i].start();
}
}
}