如何检测被IO阻塞的线程? [英] How to detect thread being blocked by IO?

查看:508
本文介绍了如何检测被IO阻塞的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,线程可以有不同的状态:

In Java, thread can have different state:

NEW,RUNNABLE,BLOCKED,WAITING,TIMED_WAITING,TERMINATED

NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED

但是,当线程被IO阻塞时,其状态为RUNNABLE。如何判断它是否被IO阻止?

However, when the thread is blocked by IO, its state is "RUNNABLE". How can I tell if it is blocked by IO?

推荐答案


  • 新:线程已创建,但尚未处理。

  • RUNNABLE:
    线程占用CPU并处理任务。 (由于操作系统的资源分配,它可能处于WAITING状态。

  • BLOCKED:线程正在等待另一个线程释放其锁定以便获取显示器锁定。 JVISULVM显示为监视

  • 等待:线程正在等待使用wait,join或park方法。

  • TIMED_WAITING:线程正在等待使用sleep,wait,join或park方法。 (与WAITING的区别在于最大等待时间由方法参数指定,WAITING可以通过时间和外部更改来缓解。)

  • TERMINATED:退出的线程处于这种状态。

    • NEW: The thread is created but has not been processed yet.
    • RUNNABLE: The thread is occupying the CPU and processing a task. (It may be in WAITING status due to the OS's resource distribution.)
    • BLOCKED: The thread is waiting for a different thread to release its lock in order to get the monitor lock. JVISULVM shows thta as Monitoring
    • WAITING: The thread is waiting by using a wait, join or park method.
    • TIMED_WAITING: The thread is waiting by using a sleep, wait, join or park method. (The difference from WAITING is that the maximum waiting time is specified by the method parameter, and WAITING can be relieved by time as well as external changes.)
    • TERMINATED: A thread that has exited is in this state.
    • 另见 http://architects.dzone.com/articles/how-analyze-java-thread-dumps

      线程转储

      转储java线程堆栈,你可以找到类似的东西

      Dumping java thread stack you can find something like that

         java.lang.Thread.State: RUNNABLE
                 at java.io.FileInputStream.readBytes(Native Method)
      

        java.lang.Thread.State: RUNNABLE
                at java.net.SocketInputStream.socketRead0(Native Method)
      

      你可以理解java正在等待回复。

      and you can understand that java is waiting response.

      我建议这个工具 Java线程转储分析器或此插件 TDA

      I suggest this tool Java Thread Dump Analyser or this plug-in TDA

      ThreadMXBean

      Yiu可以使用ThreadMXBean获取更多信息

      Yiu can obtain more information using the ThreadMXBean

      http://docs.oracle.com/javase/7/docs/api/java/lang/management/ThreadMXBean.html

      这篇关于如何检测被IO阻塞的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆