如何检测,如果另一个Java线程被挂起或冻结? [英] how to detect if another java thread is suspended or frozen?

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

问题描述

我搜索,找到方法,以确定是否另一个线程是通过添加一个布尔值,它暂停。但是,我不希望(preFER不)修改其他线程的code。而且,我需要检测,如果它是由什么原因被冻结(甚至是一个错误,所以在这种情况下,其他线程也可能是反应迟钝)。

I searched and found ways to determine if another thread is suspended by adding a boolean to it. But, I do not want (prefer not) to modify that other thread's code. And, I need to detect if it is frozen by any reason (even a bug, so in this case that other thread may also be unresponsive).

我怎么看日食做它,并显示应用程序的线程没有响应,我不知道他们是如何$ C $光盘。

I see how eclipse does it and shows the application's thread is not responding, I wonder how they coded that.

动机:我需要这个从3D LWJGL应用松开鼠标(ungrab它),而这必须是独立于任何IDE中,应用程序本身必须做到这一点。我想监视主应用程序线程。

Motivation: I need this to release the mouse (ungrab it) from a 3D lwjgl application, and this must be independent of any IDE, the application itself must do it. I am trying to monitor the main application thread.

推荐答案

虽然不一定是最好的主意,你可以使用的 发#的getState() 查看线程的当前状态。

While not necessarily the best idea, you can use Thread#getState() to view the current state of the thread.

然而,这将取决于该线程的上下文中。如果被冻结,因为它不能跳出循环,那么这种方法是行不通的。此外,如果是简单地等待锁或上一个有界集合,这将是一个虚假呼叫

However, this will depend on the context of the thread. If it is frozen because it cannot break out of a loop, then this method cannot work. Additionally, if it is simply waiting on a lock or on a bounded collection, it will be a false call.

线程应该在这3种状态:的 BLOCKED ,的 等待 或的 TIMED_WAITING

The thread should in these 3 states: BLOCKED, WAITING, or TIMED_WAITING.

这篇关于如何检测,如果另一个Java线程被挂起或冻结?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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