views:

61

answers:

2

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.

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?

+4  A: 

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

It does have the requirement of adding:

RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());

to your code however.

TofuBeer
This one worked pretty good. I have already found some violations.
Justin
+3  A: 

I've found a 4 years old blog post describing some solutions, but would be really interested if you find one which detects the most EDT violations. The RepaintManager seems not to be bullet proof in detecting all violations.

Tobias P.
Is it known what kinds of cases the RepaintManager fails to detect?
Justin
These solutions look really good, but more difficult to implement quickly.
Justin