class ThreadDemo {
public static void main(String[] args) {
Thread1 a = new Thread1();
Thread1 b = new Thread1();
Thread1 c = new Thread1();
Thread1 d = new Thread1();
a.start();
b.start();
c.start();
d.start();
}
}
class Thread1 extends Thread{
static int ticket = 100 ;
public void run(){
while (true) {
if (ticket>0) {
System.out.println("thread..."+currentThread().getName()+"...."+ticket);
ticket--;
}
}
}
}为什么我打印的的ticket都是每个线程都是从100开始呢?明明静态修饰了啊,不应该是四个线程和起来打印从1到100吗? |
|