I copied a TableColumnAdjuster class which seems to be pretty popular. http://tips4java.wordpress.com/2008/11/10/table-column-adjuster/
However, the JTables I am developing are dynamic and can have a large amount of data flow in and out of them (as much as 30,000 records). Obviously, when the TableColumnAdjuster has to iterate through every cell it can take awhile and make the Swing interface unresponsive. I tried putting the adjustColumns() method on its own thread, but the columns began to resize wildly and randomly. Obviously not threadsafe. So I started to reverse engineer the class, turning variables into volatiles, replacing the hashmap with a concurrent hash map, and separating the calculation from the Swing invokeLater() thread.
However, nothing is working and the columns still resize wildly. I'm beginning to wonder if the JTable is not threadsafe altogether. Is JTable even threadsafe for tasks like this? Is there a somewhat simple, strategic insertion of code to make the adjustColumns() run on a separate thread safely? And interact with the Swing thread when it has updates for the view?