日期:2014-05-20  浏览次数:20772 次

新手求助线程输出
class MyThread implements Runnable{
private String name;
private int time;
public MyThread(String name,int time){
this.name=name;
this.time=time;
}
public void run(){
try{
Thread.sleep(this.time) ;
}
catch(InterruptedException e){
e.printStackTrace();
// System.out.println(this.name+"休眠"+this.time);
}
System.out.println(this.name+"休眠"+this.time);
}
}
public class Demo3 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MyThread my1=new MyThread("t1",10000);
MyThread my2=new MyThread("t2",20000);
MyThread my3=new MyThread("t3",30000);
Thread t1=new Thread();
Thread t2=new Thread();
Thread t3=new Thread();
t1.start();
t2.start();
t3.start();
}

}

输出时候应为 t1休眠10000 。。。。 实际eclipse运行结果为空,新手求助

------解决方案--------------------
我发现你的线程里面没有接收对象!
Thread t1=new Thread(my1);
Thread t2=new Thread(my2);
Thread t3=new Thread(my3);