标题: 多线程问题 [打印本页] 作者: 18201432758 时间: 2015-9-15 14:58 标题: 多线程问题 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吗?作者: 程序猿小哲 时间: 2015-9-15 16:03
要想合起来的话,用实现runnable接口的方法