不同意, java没有什么main线程。 我的观点是: 这个线程因为没有捕获异常,而结束了。 简而言之,就是这个线程结束了。程序是否会结束,要看是所有其他线程都是 daemon 线程;如果不是,就不会退出。 贴段jdk中代码加注释, /** * Marks this thread as either a daemon thread or a user thread. The * Java Virtual Machine exits when the only threads running are all * daemon threads. * <p> * This method must be called before the thread is started. * <p> * This method first calls the <code>checkAccess</code> method * of this thread * with no arguments. This may result in throwing a * <code>SecurityException </code>(in the current thread). * * @param on if <code>true</code>, s this thread as a * daemon thread. * @exception IllegalThreadStateException if this thread is active. * @exception SecurityException if the current thread cannot modify * this thread. * @see #isDaemon() * @see #checkAccess */ public final void setDaemon(boolean on) { checkAccess(); if (isAlive()) { throw new IllegalThreadStateException(); } daemon = on; }
其他线程就是该线程断掉
不同意, java没有什么main线程。
我的观点是: 这个线程因为没有捕获异常,而结束了。 简而言之,就是这个线程结束了。程序是否会结束,要看是所有其他线程都是 daemon 线程;如果不是,就不会退出。
贴段jdk中代码加注释, /**
* Marks this thread as either a daemon thread or a user thread. The
* Java Virtual Machine exits when the only threads running are all
* daemon threads.
* <p>
* This method must be called before the thread is started.
* <p>
* This method first calls the <code>checkAccess</code> method
* of this thread
* with no arguments. This may result in throwing a
* <code>SecurityException </code>(in the current thread).
*
* @param on if <code>true</code>, s this thread as a
* daemon thread.
* @exception IllegalThreadStateException if this thread is active.
* @exception SecurityException if the current thread cannot modify
* this thread.
* @see #isDaemon()
* @see #checkAccess
*/
public final void setDaemon(boolean on) {
checkAccess();
if (isAlive()) {
throw new IllegalThreadStateException();
}
daemon = on;
}
可以它是最先启动的,但是它结束了,并不代表程序要一定要结束。