线程之间有异常不影响?

aotian16 2011-01-14 10:36:21

/**
*
*/
package pk.testthread;

/**
* @author admin
*
*/
public class TestThread {

public static String string;

/**
* @param args
*/
public static void main(String[] args) {

Thread thread = new Thread(new Runnable() {

@Override
public void run() {
System.out.println("in son thread : start");

// NullPointerException
System.out.println(string.toString());

System.out.println("in son thread : end");
}
});

System.out.println("in main thread : start");

thread.start();
// try {
// thread.join();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }

System.out.println("in main thread : end");
}
}

我还以为有个线程出异常就退出了呢!
书上也没看到这方面的信息!
高手指教下
...全文
67 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
aotian16 2011-01-14
  • 打赏
  • 举报
回复
多谢
totaka 2011-01-14
  • 打赏
  • 举报
回复
* When a Java Virtual Machine starts up, there is usually a single
* non-daemon thread (which typically calls the method named
* <code>main</code> of some designated class). The Java Virtual
* Machine continues to execute threads until either of the following
* occurs:
* <ul>
* <li>The <code>exit</code> method of class <code>Runtime</code> has been
* called and the security manager has permitted the exit operation
* to take place.
* <li>All threads that are not daemon threads have died, either by
* returning from the call to the <code>run</code> method or by
* throwing an exception that propagates beyond the <code>run</code>
* method.
* </ul>
qybao 2011-01-14
  • 打赏
  • 举报
回复
线程出异常,线程本身退出了,但你这个程序中,主线程没受影响,当然会继续了

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧