public class ThreadTest implements Runnable {
int a;
public void run() {
for(a=0;a<10;a++){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
System.out.println(Thread.currentThread().getName() + " a=" + a);
}
}public static void main(String[] args) {
ThreadTest run=new ThreadTest();
Thread thread1=new Thread(run);
Thread thread2=new Thread(run);
Thread thread3=new Thread(run);
Thread thread4=new Thread(run);
Thread thread5=new Thread(run);
Thread thread6=new Thread(run);
thread6.start();
thread1.start();
thread2.start();
thread3.start();
thread4.start();
thread5.start();}
}
为什么会输出到a=14啊
int a;
public void run() {
for(a=0;a<10;a++){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
System.out.println(Thread.currentThread().getName() + " a=" + a);
}
}public static void main(String[] args) {
ThreadTest run=new ThreadTest();
Thread thread1=new Thread(run);
Thread thread2=new Thread(run);
Thread thread3=new Thread(run);
Thread thread4=new Thread(run);
Thread thread5=new Thread(run);
Thread thread6=new Thread(run);
thread6.start();
thread1.start();
thread2.start();
thread3.start();
thread4.start();
thread5.start();}
}
为什么会输出到a=14啊
a可能的取值范围应该是[10,15]。一般13,14,15会多一些