CodeBuddy CodeBuddy - 2 months ago 20
Java Question

Best practise for updating data in a AbstractTableModel in a non AWT thread

I've sub classed

for use as the model for my
. Whenever data is added to I call
in the AWT thread. All access to my underlying container is made thread safe by using synchronized methods.

This pattern has been working fine for me so far. However now I want to remove data from the list I've realized I have a threading issue. If I remove a row and call
in the AWT thread I can still get a call to
for a row index that now no longer exists.

What is best practice for performing operation on a the table model outside the AWT thread?


The best practice IMHO is to avoid doing it. Wrap every access to the model from another thread inside a Runnable and use SwingUtilities.invokeLater to update the model.