rediVider
rediVider

Reputation: 1307

Java Swing/EDT event handling synchronization

We've found a ConcurrentModificationException exception in our GUI log which seems to be related to changing the list backing a table model.

The order seems to be:

  1. event1 triggers backing list iteration and altering of the list
  2. Altering the list triggers an event2 that interrupts the current execution (a byproduct event of the alteration). This event is handled before processing of event1 concludes
  3. event2 alters the list as well.
  4. event1 gets control and continues its iteration, which blows up because the backing list has changed

Since they are both on the EDT, if I use synchronized keyword (or a lock), in both places, will event2 give up and let event1 processing continue, or will I have created a fancy deadlock?

Upvotes: 0

Views: 249

Answers (1)

camickr
camickr

Reputation: 324207

seems to be related to changing the list backing a table model.

You should not be changing the List. All updates should be done directly on the model.

In many cases when you have a ConcurrentModificationExecption you can wrap that code in a SwingUtilities.invokeLater() so the code gets added to the end of the EDT allowing the first event to finish processing.

Upvotes: 2

Related Questions