当我run()
通过调用时,我得到了输出t.start()
,但没有得到相同的输出obj.start()
。可能是什么原因?
谁能解释一下?
class Ex1 implements Runnable {
int n;
String s;
public void run(){
for(int i=1;i<=n;i++){
System.out.println( s +"-->"+ i);
}
}
}
class RunnableDemo extends Thread {
Ex1 e;
RunnableDemo(Ex1 e) {
this.e = e;
}
public static void main(String[] args) {
Ex1 obj1 = new Ex1();
Ex1 obj2 = new Ex1();
obj1.n = 5;
obj1.s = "abc";
// Thread t = new Thread(obj1);
// t.start();
RunnableDemo obj = new RunnableDemo(obj1);
obj.start();
}
}