gpt4 book ai didi

java - Java线程什么时候空闲?

转载 作者:搜寻专家 更新时间:2023-10-31 08:15:17 24 4
gpt4 key购买 nike

只是通过 Java 查看 thread states :

NEW
A thread that has not yet started is in this state.
RUNNABLE
A thread executing in the Java virtual machine is in this state.
BLOCKED
A thread that is blocked waiting for a monitor lock is in this state.
WAITING
A thread that is waiting indefinitely for another thread to perform a particular action is in this state.
TIMED_WAITING
A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state.
TERMINATED
A thread that has exited is in this state.

怎么没有idle状态呢?或者什么状态最接近于空闲线程?
RUNNING 是否在 CPU 上执行?

最佳答案

撇开 NEWTERMINATED 不谈,“idle”的意思是“等待东西”。这包括以下所有内容:

BLOCKED
WAITING
TIMED_WAITING

Is RUNNING but just not executing on CPU?

没有RUNNING,只有RUNNABLE。这大致意味着“有事情要做”,但没有说明线程现在是否实际上正在运行(它可能正在等待核心可用)。

关于java - Java线程什么时候空闲?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15701064/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com