考慮下面的代碼:異常在Java線程
public class ThreadT implements Runnable {
public void run() {
System.out.println("run.");
throw new RuntimeException("Problem");
}
public static void main(String[] args) {
Thread t = new Thread(new ThreadT());
t.start();
System.out.println("End of method.");
}
}
我得到的輸出是:
End of method.
run.
Exception in thread "Thread-0" java.lang.RuntimeException: Problem
爲什麼輸出是不喜歡這樣的:
run.
Exception in thread "Thread-0" java.lang.RuntimeException: Problem
End of method.
[高度相關](http://stackoverflow.com/questions/20563287/why-arent-the-calls-in-main-sequential)。 – ChiefTwoPencils
如果你不想讓它獨立運行,你爲什麼要使用一個線程? –