如何查看事件线程上运行的所有内容

发布于 2024-11-01 19:17:11 字数 232 浏览 7 评论 0原文

我们遇到了一个错误,我们无法追踪到哪里有东西冻结了我们的 swing 线程(现在已经快两周了,没有真正的结果) - 我们是经验丰富的 Swing 程序员,但我们有一个庞大的程序,并且相信它存在于某些 我想知道,除了编辑 JDK 中的实际 EventQueue

之外,还有什么方法可以让我们查看当前在事件调度线程上运行的所有代码片段 - 也许是某种类型的允许我们在事物进入或离开事件调度线程时查看事物的工具?

We are experiencing a bug we cannot track down where something is freezing up our swing thread (it's been almost 2 weeks now and no real results) - we are experienced Swing programmers but we have a huge program and believe it to be in some of the legacy code

I am wondering, is there any way outside of editing the actual EventQueue class in the JDK which will allow us to view all pieces of our code currently running on the Event Dispatch Thread - maybe some type of tool which will allow us to view things as they enter or leave the event dispatch thread?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

水水月牙 2024-11-08 19:17:11

一种有趣的方法是扩展 EventQueuepush() 它,如此处所示。

One interesting approach is to extend EventQueue and push() it, as shown here.

冷默言语 2024-11-08 19:17:11

记录通过事件调度线程的所有内容似乎是诊断冻结的一种麻烦方法。等到问题发生,然后询问事件调度线程它现在在做什么不是更容易吗?一种方法是启用 JMX 监控,使用 JMX 客户端连接到正在运行的进程,例如 VisualVM (随 JDK 一起提供),等待发生问题,然后进行线程转储

如果您仍然希望记录事件分派线程正在执行的所有操作,可以通过以下方式执行此操作:

  1. 在 Eclipse 中,以调试模式启动应用程序。
  2. EventQueue.dispatchEvent上创建断点,右键单击它,选择“属性”,选中“条件”,然后输入以下“条件”:

    System.out.println(arg0);
    返回假;
    

Logging everything that passes through the Event Dispatch Thread seems a cumbersome way to diagnose a freeze. Wouldn't it be easier to wait until the problem occurs, and then ask the Event Dispatch Thread what it's doing now? One way to do this is to enable JMX monitoring, connect to your running process with a JMX client such a VisualVM (which ships with the JDK), wait for the problem to occur, and then take a thread dump.

In case you still wish to log everything the Event Dispatch Thread is doing, you can do this by:

  1. In Eclipse, launch the application in debug mode.
  2. Create a breakpoint on EventQueue.dispatchEvent, right-click it, select "properties", check "condition", and enter the following "condition":

    System.out.println(arg0);
    return false;
    
忱杏 2024-11-08 19:17:11

尝试 BTrace 来检测 EventQueue 并在每次添加内容时捕获堆栈跟踪可能是个好主意。我认为最新的 VisualVM 具有允许您使用 BTrace 脚本检测正在运行的 JVM 的插件。

It might be good idea to try BTrace to instrument the EventQueue and capture stack traces each time something gets added. I think the latest VisualVM has plugins that will allow you to instrument a running JVM with a BTrace script.

橙味迷妹 2024-11-08 19:17:11

如果您使用的是 Oracle JRE,则有一个 TracedEventQueue已经包括在内。您可以按照前面提到的方式安装它:

EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
eventQueue.push(new TracedEventQueue());

注意,这将输出很多输出...

If you're using the Oracle JRE, there is a TracedEventQueue included already. You can install it as mentioned before:

EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
eventQueue.push(new TracedEventQueue());

Note, this will output a lot of output...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文