gpt4 book ai didi

java - 为什么 jstack out 说线程状态是 "RUNNABLE"而 socketRead

转载 作者:行者123 更新时间:2023-12-01 08:07:00 24 4
gpt4 key购买 nike

我有以下堆栈跟踪,线程在套接字读取时阻塞,为什么它的状态是“RUNNABLE”而不是“BLOCKED”?

    "Thread-80" daemon cpu=390.00 [reset 390.00] ms elapsed=6724.68 [reset 6724.68] s allocated=8140992 B (7.76 MB) [reset 8140992 B (7.76 MB)] defined_classes=81io= file i/o: 130069/0 B, net i/o: 314790/394506 B, files opened:0, socks opened:0  [reset file i/o: 130069/0 B, net i/o: 314790/394506 B, files opened:0, socks opened:0 ] prio=6 tid=0x000000002bbeb000 nid=0x35f4 / 13812 runnable  [_thread_in_native (_at_safepoint), stack(0x0000000032630000,0x00000000326a0000)] [0x000000003269e000]"Thread-80" daemon cpu=390.00 [reset 390.00] ms elapsed=6724.68 [reset 6724.68] s allocated=8140992 B (7.76 MB) [reset 8140992 B (7.76 MB)] defined_classes=81io= file i/o: 130069/0 B, net i/o: 314790/394506 B, files opened:0, socks opened:0  [reset file i/o: 130069/0 B, net i/o: 314790/394506 B, files opened:0, socks opened:0 ] prio=6 tid=0x000000002bbeb000 nid=0x35f4 / 13812 runnable  [_thread_in_native (_at_safepoint), stack(0x0000000032630000,0x00000000326a0000)] [0x000000003269e000]   java.lang.Thread.State: RUNNABLE    at java.net.SocketInputStream.socketRead0(Ljava/io/FileDescriptor;[BIII)I(Native Method)    at java.net.SocketInputStream.read([BIII)I(SocketInputStream.java:150)    - additional info (remote: default/127.0.0.1:56462, local: localhost/127.0.0.1:2001)    at java.net.SocketInputStream.read([BII)I(SocketInputStream.java:121)    - additional info (remote: default/127.0.0.1:56462, local: localhost/127.0.0.1:2001)    at sun.security.ssl.InputRecord.readFully(Ljava/io/InputStream;[BII)I(InputRecord.java:442)    at sun.security.ssl.InputRecord.read(Ljava/io/InputStream;Ljava/io/OutputStream;)V(InputRecord.java:480)    at sun.security.ssl.SSLSocketImpl.readRecord(Lsun/security/ssl/InputRecord;Z)V(SSLSocketImpl.java:927)

最佳答案

因为这就是它应该的样子。

Thread.State.BLOCKED 表示线程正在等待监视器锁。它与套接字上的阻塞 I/O 没有任何关系。

来自Javadoc for Thread.State :

public static final Thread.State BLOCKED

Thread state for a thread blocked waiting for a monitor lock. A thread in the blocked state is waiting for a monitor lock to enter a synchronized block/method or reenter a synchronized block/method after calling Object.wait.

另一方面,

Thread.State.RUNNABLE 表示它正在执行(但可能正在等待 I/O):

public static final Thread.State RUNNABLE

Thread state for a runnable thread. A thread in the runnable state is executing in the Java virtual machine but it may be waiting for other resources from the operating system such as processor.

关于java - 为什么 jstack out 说线程状态是 "RUNNABLE"而 socketRead,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20795295/

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