Brief description of a problem.
Assume we have JTable and user interacting with it in some way. TableModel of this table is constantly changing. How to ensure that when user tries to get some info from the table by referencing some constant column and currently selected row (by its rowIndex he got from JTable), he will not get into situation when TableModel is changed and his rowIndex obtained from JTable is no longer corresponding to same value in TableModel.
Following is initial question which explains problem in more detail:
Consider following situation:
There is JTable which shows user info about currently running requests in some system
When new request enters system, new row is being added to the table
user can interact with table by right-clicking on a row (single row selection model is used in table) and choosing option from the menu (like: abort, postpone, retry, etc.)
there is separate class which implements ActionListener interface (listens to the table) and handles all user interactions
When user does some action on the table this class checks currently selected row and assigns some values for user's action (basically it takes index of selected row and then calls tableModel.getValueAt(indexOfSelectedRow, someValuableDataColumnIndex))
Now consider scenario when system is under stress test and requests are being submitted constantly with big frequency. This, in my case, leads to a bug, when sometimes class which handles user's actions gets wrong info from table model (action was called on one row, but action is done for another, usually next one). I believe this happens because during some inits in action handling class table model is changed because of new request accepted.
Question is, how to fix this. I am thinking about two approaches:
use something like invokeAndWait() for initialization in my user actions' handling class (don't like this idea, because imo it will lead to other unpredictable bugs)
creating separate listener class which will listen to user selections in the table and store data from selected row as soon as it was selected separately from TableModel. This way actions handling class will take data not from table model which is being changed, but from selected row, which is constant during the described scenario. (not sure this idea will work)
Please, comment on my ideas, and suggest yours.
I am sorry for absence of any code here, but original code will take way too much space, and model example isn't something what can be done easily here.