简体   繁体   English

是否有一种干净的方法来检索AWT事件派发线程

[英]Is there a clean way to retrieve the AWT event dispatch thread

I'm trying to do some monitoring of the AWT Event Dispatch Thread's (EDT) health from a separate thread. 我正在尝试从一个单独的线程监视AWT事件调度线程(EDT)运行状况。 If I start missing heartbeats I want to dump the EDT stack trace. 如果我开始丢失心跳,我想转储EDT堆栈跟踪。 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). 问题是EventQueue没有公开检索当前调度线程的方法,该方法是包私有(可能有充分理由)。 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: 因此,我可以搜索所有线程并查找名称类似于AWT-EventQueue-X的线程,或者使用invokeLater或invokeAndWait并让我的runnable保存线程,例如:

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. 然后,每次我去转储线程堆栈时,我必须首先确保我得到的EDT仍然存活,如果没有再次完成整个过程来获取线程。 I'm just looking for a cleaner way to do this. 我只是想找一个更干净的方法来做这件事。

或者,你可以扩展EventQueue ,如图所示这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM