Name: vi73552 Date: 03/09/99
The BINGO demo in Java Tutorial updates a Swing component in a thread other than the event thread.
The PlayerListenerThread (*NOT* the event thread) in the BINGO example can deliver tableChanged events to the cardsAndPlayers table. The sequence of events is:
playerListenerThread
=> playerInfoPane.updatePlayer()
=> playerInfoModel.updatePlayer()
=> cardsAndPlayers.tableChanged()
JTable.tableChanged is not completely thread safe: it is not synchronized and it may call getRowHeight() and getColumnModel() - to name a couple - which are not synchronized. It looks like tableChanged is designed to be called in the event thread, as one would expect given the single-threaded design of swing.
The "Safe to call from any thread" comments in PlayerInfoPane are wrong. As a rule, all listeners in Swing should be able to count on being called in the event thread. To ensure this, the PlayerInfoModel should be updated (or cleared) from the event thread only. Working backward, the playerListenerThread should use invokeLater to invoke the (PlayerInfoPane) notifyee's updatePlayer method in the event thread.
(Review ID: 53336)
======================================================================