[concurrency-interest] Confused about Component.getTreeLock()

Gregg Wonderly gregg at cytetech.com
Tue Mar 6 10:27:02 EST 2007

David Holmes wrote:
> Peter,
> The AWT was intended to be multi-threadsafe and does not enforce the
> "everything must happen in the event thread rule". That was a mistake that
> Swing rectified. So many of the AWT components use locks and the
> component-tree uses the TreeLock. The problem with the tree-lock is that its
> client--side synchronzation (all clients have to know when they should
> acquire it) and yet there is no documentation telling clients when they need
> to acquire it.

The standing statement from the swing development team WAS that you should never 
touch a "realized" component without using the event dispatch thread.  As of 
JDK1.5, they've ammended this statement to demand that anything which can cause 
a component to be realized must be in the event dispatch thread.  This includes 
things like Window.pack() and Window.setVisible(true).

Gregg Wonderly

More information about the Concurrency-interest mailing list