0
点赞
收藏
分享

微信扫一扫

Jdk源码之Thread类详解

拾光的Shelly 2022-01-28 阅读 70


Jdk源码之Thread类详解

  • ​setDaemon()​​方法的释义
/**
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
*/
  • ​setDaemon()​​方法的代码
public final void setDaemon(boolean on) {
checkAccess();
if (isAlive()) {
throw new IllegalThreadStateException();
}
daemon = on;
}



举报

相关推荐

0 条评论