为什么jstack表示线程状态是“RUNNABLE”而socketRead

时间:2013-12-27 05:26:57

标签: java

我有以下堆栈跟踪,线程在套接字读取时阻塞, 为什么它的状态是“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=81
io= 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=81
io= 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)

1 个答案:

答案 0 :(得分:5)

因为那是应该的。

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

来自Javadoc for Thread.State

  

public static final Thread.State BLOCKED

     

线程的线程状态被阻塞等待监视器锁定。处于阻塞状态的线程正在等待监视器锁定以进入同步块/方法或在调用Object.wait后重新输入同步块/方法。

另一方面,

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

  

public static final Thread.State RUNNABLE

     

可运行线程的线程状态。处于可运行状态的线程正在Java虚拟机中执行,但它可能正在等待来自操作系统的其他资源,例如处理器。