How to monitor Event Dispatch Thread queue?

百般思念 提交于 2019-12-02 08:01:16

Typically the slowness is caused by code that inadvertently tries to access the filesystem, network or database from the UI thread. Its usually pretty easy to fix with SwingWorkers once the cause has been identified.

Replace the Event Dispatch Queue with an implementation that monitors how long events in the queue take to process.

When an event takes too long the new queue implementation logs the stacktrace of the EDT.
If you are only used to looking at stacktraces when exceptions are thrown don't get alarmed. The new implementation isn't killing slow events or causing them to throw exceptions its just showing you what the EDT is doing at the moment when the unresponsiveness was detected. Look at the printed stacktraces and figure out how to move the slow part of the event into another thread.

I believe Netbean's slowness detector implements something very similar.

You need to provide more details...but thread themselves don't have queues. You can not check to see what work is waiting on a thread, you can only check the status of any given thread (say in a thread pool).

If you have a concept of "work" that needs to be queued for eventually processing by a given "worker" (ie thread) you have to implement that yourself. Alternatively you can use a an actor system such AKKA which sounds like it would do what you require

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!