TableModel fireXXX() skips event queue

Upon mouse click, hardware/OS pumps in a low-level event into EDT queue. After some delay the mouse event is picked up on EDT. The event is examined to get the source which is typically some jcomponent [1]. Then the list of listeners is examined. Each listener object’s mouseClicked() method is invoked sequentially on EDT.

However, in a TableModel’s fireXXX() method, the listener object’s [2] event handler method is invoked directly — on the same thread (as part of) fireXXX(), without pumping event into the queue.

Hold your breath — if you call fireXXX() on any non-EDT, the view (java + native screen objects) would be modified on that thread — disaster. Therefore TableModel should be modified only on EDT.

[1] remember when user clicks, there has to be some screen object she’s hitting.
[2] This object is the JTable instance, i.e. the view object. This object is __automatically__ registered as one of the listeners on the table model object. If the table model instance is a celebrity with a fan club, then JTable instance is her twin sister and the founding member of the fan club.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s