class tickte implements Runnable{
private int tickets=100;
public void run(){
for(int i=1;i<tickets;tickets--){
System.out.println(Thread.currentThread().getName()+"-----"+tickets);
}
}
}
public class 线程_2 {
public static void main(String[] args){
tickte t=new tickte();
Thread t1=new Thread(t);
Thread t2=new Thread(t);
Thread t3=new Thread(t);
Thread t4=new Thread(t);
t1.start();
t2.start();
t3.start();
t4.start();
创建线程声明实现了Runnable接口的类。覆盖了接口中的run方法。为什么用Runnable接口做会打印多个100呢? 求高手指点??? |
|