如何检测Swing线程策略违规 [英] How to detect Swing thread policy violations

查看:104
本文介绍了如何检测Swing线程策略违规的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种自动的方式来检测在我的代码中Swing的单线程策略的违规。我正在寻找一些沿着一些AOP代码的东西,当你在秋千应用程序运行时,你可以将其放入虚拟机,并记录在EDT之外修改swing组件的任何地方。

I am looking for an automatic way to detect violations of the Swing's single threaded policy in my code. I'm looking for something along the lines of some AOP code you drop into the VM while the swing app is running and have it log any places where a swing component is modified outside of the EDT.

我不是一个AOP的人,但我会想象在每个java.swing。*类创建一个AOP代理,看起来像

I'm not an AOP guy but I would imagine creating an AOP proxy around every java.swing.* class which looks like

AOP_before(Method m, Object args[]) {
 if (!isEventDispatchThread(Thread.currentThread()) {
  logStack(new RuntimeException("violation!"));
 }

 invoke(m, args);
}



Anyone know of a project or utility that does this?

推荐答案

我没有使用这个特定的项目,但是这个 CheckThreadViolationRepaintManager 应该诀窍。

I haven't used this particular one, but this CheckThreadViolationRepaintManager should do the trick.

它的要求是加入:

RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());

到您的代码。

这篇关于如何检测Swing线程策略违规的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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