public class SigleThread extends Thread {
@Override
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println(i);
try {
join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public class Test {
public static void main(String[] args) {
SigleThread sing = new SigleThread();
sing.start();
}
}
这个时候控制台在输出0之后....就会处于卡死状态....为什么会这样????求大神解惑~~~
而换成下面这种调用方式就没问题....
public class Test {
public static void main(String[] args) {
Runnable sing = new SigleThread();
Thread t = new Thread(sing);
t.start();
}
}
这种调用就会打印0 1 2 3 4 5然后正常结束....请问到底是什么原理??