有没有一种干净的方法来检索 AWT 事件调度线程
我正在尝试从单独的线程对 AWT 事件调度线程 (EDT) 的运行状况进行一些监视。如果我开始丢失心跳,我想转储 EDT 堆栈跟踪。问题是 EventQueue 没有公开检索当前调度线程的方法,该方法是包私有的(可能有充分的理由)。因此,我可以搜索所有线程并查找名称如 AWT-EventQueue-X 的线程,或者使用 invokeLater 或 invokeAndWait 并让我的可运行保存脱离线程,类似于:
EventQueue.invokeLater(new Runnable() {
public void run() {
eventDispatchThread = Thread.currentThread();
}
});
然后每次我去转储线程时我必须首先确保我获得的 EDT 仍然有效,如果没有,请再次执行整个过程以获取线程。我只是在寻找一种更清洁的方法来做到这一点。
I'm trying to do some monitoring of the AWT Event Dispatch Thread's (EDT) health from a separate thread. If I start missing heartbeats I want to dump the EDT stack trace. The problem is the EventQueue doesn't expose a way to retrieve the current dispatch thread, the method that does is package private (probably for good reason). So I can either search through all the threads and look for a thread with a name like AWT-EventQueue-X or use an invokeLater or invokeAndWait and have my runnable save off the thread, something like:
EventQueue.invokeLater(new Runnable() {
public void run() {
eventDispatchThread = Thread.currentThread();
}
});
Then every time I go to dump the thread stack I have to first make sure the EDT I've got is still alive and if not go through the whole process again to get the thread. I'm just looking for a cleaner way to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者,您可以扩展
EventQueue
,如此处所示。Alternatively, you can extend
EventQueue
, as shown here.