Jdk源码之Thread类详解
原创
©著作权归作者所有:来自51CTO博客作者说文科技的原创作品,请联系作者获取转载授权,否则将追究法律责任
Jdk源码之Thread类详解
/**
Marks this thread as either a linkplain #isDaemon daemon thread
or a user thread. The Java Virtual Machine exits when the only
threads running are all daemon threads.
标记这个线程作为一个linkplain isDaemon() daemon线程或者是一个用户线程。仅仅当运行的线程是所有的守护线程时,java虚拟机则会退出。
This method must be invoked before the thread is started.
这个方法必须在线程被启动时调用。
@param on
if {@code true}, marks this thread as a daemon thread
如果参数on为true,则标记这个线程是一个守护线程
@throws IllegalThreadStateException
if this thread is {@linkplain #isAlive alive}
@throws SecurityException
if {@link #checkAccess} determines that the current
thread cannot modify this thread
*/
public final void setDaemon(boolean on) {
checkAccess();
if (isAlive()) {
throw new IllegalThreadStateException();
}
daemon = on;
}