javax.swing.SwingUtilities.invokeAndWait
March 26th, 2007, 3:22 pmConsider the invokeAndWait method in the javax.swing.SwingUtilities class:
You give it a Runnable, and Java will execute it in the event thread, and then return to you once that is done. This normally works, but what if you call the method from the event thread? In that case, Java will put the Runnable at the end of the event queue, and then wait for it to be executed, but it never will be executed, because the current event is waiting for that Runnable to finish. Calling javax.swing.SwingUtilities.invokeAndWait from within the event thread is a recipe for an instant deadlock!
Therefore, the concurrency invariant for that method is “do not run it in the event thread”.
This invariant can be ensured by prefixing the invokeAndWait method with the Concutest ThreadChecker annotation @NotEventThread:
- package javax.swing;
- import edu.rice.cs.cunit.threadCheck.predicates.NotEventThread;
- // ...
- // ...
- @NotEventThread
- // ...
- }
- // ...
- }

