java线程转储的评估
我得到了一个进程的线程转储。它有一堆这样的线。我猜他们保留了一堆记忆,所以我得到了很多东西java线程转储的评估,java,thread-dump,Java,Thread Dump,我得到了一个进程的线程转储。它有一堆这样的线。我猜他们保留了一堆记忆,所以我得到了很多东西 "Thread-8264" prio=6 tid=0x4c94ac00 nid=0xf3c runnable [0x4fe7f000] java.lang.Thread.State: RUNNABLE at java.util.zip.Inflater.inflateBytes(Native Method) at java.util.zip.Inflater.inflate(Infl
"Thread-8264" prio=6 tid=0x4c94ac00 nid=0xf3c runnable [0x4fe7f000]
java.lang.Thread.State: RUNNABLE
at java.util.zip.Inflater.inflateBytes(Native Method)
at java.util.zip.Inflater.inflate(Inflater.java:223)
- locked <0x0c9bc640> (a java.util.zip.Inflater)
at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.read(ZipArchiveInputStream.java:235)
at com.my.ZipExtractorCommonsCompress.extract(ZipExtractorCommonsCompress.java:48)
at com.my.CustomThreadedExtractorWrapper$ExtractionThread.run(CustomThreadedExtractorWrapper.java:151)
Locked ownable synchronizers:
- None
"Thread-8241" prio=6 tid=0x4c94a400 nid=0xb8c runnable [0x4faef000]
java.lang.Thread.State: RUNNABLE
at java.util.zip.Inflater.inflateBytes(Native Method)
at java.util.zip.Inflater.inflate(Inflater.java:223)
- locked <0x0c36b808> (a java.util.zip.Inflater)
at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.read(ZipArchiveInputStream.java:235)
at com.my.ZipExtractorCommonsCompress.extract(ZipExtractorCommonsCompress.java:48)
at com.my.CustomThreadedExtractorWrapper$ExtractionThread.run(CustomThreadedExtractorWrapper.java:151)
Locked ownable synchronizers:
- None
如果可能的话,我建议您尝试使用jvisualvm(它位于JDK安装的bin文件夹中)。它可以连接到任何本地java进程,并向您提供线程信息和内存信息(使用情况、分配的对象等)。接口比控制台转储更容易解释。关于您的问题: Thread.State的定义在API中:
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.
因此,上面跟踪中的两个线程是活动的(注意runnable意味着它们可以运行,而不一定是在运行,即OS调度程序可能会在另一个线程执行时暂停它们)
“杀死”线程的可能方法:
- 有一个意外的例外
- 调用线程的停止()
- 让线程正常完成执行(即退出run()
thread.stop()
杀死一个线程,但该线程可能会抵制,而且它本身就不安全,不推荐使用,而且非常糟糕。不要这样做。此外,我不确定当线程在本机方法中时它是否有效,这里就是这样
Thread.interrupt()
轻推目标线程。线程在下一次显式查看中断标志或执行某些可能的阻塞操作(I/O或wait()
)时会注意到它。线程可能捕获异常并忽略它
你的线程是“可运行的”:它们没有被阻塞<代码>充气器。充气()无论如何都不是一个阻塞功能;它只执行内存计算。本机实现中可能存在错误(Inflater.inflateBytes()
),但这不太可能,因为这依赖于一段非常稳定的代码)。更合理的是,其中一个调用者(例如,您的zipextractorcommoncompress
类)陷入了一个循环中,它要求Zip提取器再处理零个字节,并且不理解在重试之前应该等待更多的数据
有没有可靠的方法可以真正杀死线程
不,没有
正如您所观察到的,Thread.interrupt()
建议线程停止,但它可能没有注意到,或者决定不注意
唯一的另一种选择是Thread.stop()
,这是不推荐的,因为它会严重破坏应用程序的稳定性。具体来说,Thread.stop()
会释放所有线程锁,而不保证锁所保护的状态处于合适的状态。同时,意外异常意味着被stop()
中断的方法没有机会(例如)notify()
其他正在等待的线程。最后,线程可以捕获(而不是重新抛出)ThreadDeath
异常对象,从而导致stop()
根本不停止线程
简而言之,调用
Thread.stop()
是一个非常非常糟糕的主意。线程转储是用jvisualvm完成的……我的进程在执行堆转储时结束
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.