Pedantic Swing threading question

From: Laird Nelson (lairdnelson_at_comcast.net)
Date: 12/29/03


Date: Mon, 29 Dec 2003 09:05:25 -0500

Hello; hope everyone had a good holiday season.

I am familiar with Swing threading issues except for this one point.

Suppose you have a class, A, that registers itself (or another tiny
class) as a PropertyChangeListener on another class, B. Suppose that
this PropertyChangeListener's job is to react to the property change
event by updating the GUI.

Strictly speaking, shouldn't the body of the propertyChange() method
always check to see if it's running on the event dispatch thread (EDT)
before actually attempting to update the GUI?

Now, I know that in most Swing applications, this is rarely a
concern--some text property changes somewhere and the listener simply
calls something like, say, JLabel.setText(), and that's a quick enough
call that it would probably be overkill to call
SwingUtilities.invokeLater(). But I'm interested in the...theory, I
guess, more than the actual practice. For this thought experiment,
assume that the propertyChange() event may be invoked on a different thread.

Hope this question makes sense.

Cheers,
Laird