multithreaded tablemodel - mutexes?

Hi

Ok I have a JTable with a TableModel extending DefaultTableModel.

All my calls goes through JTable to TableModel.

for example:

first invoked:

//In JTable

publicvoidsynchronized doSomethingWithRows()

{

int rows = tableModelName.getAllRows();

for(k=0; k<rows; k++)

{

System.out.println("TESTING!");

}

}

PROBLEM: In the above method doSomethingWithRows an OutOfBoundsException can occur ! because apparently the TableModel can change meanwhile(even though I have synchronized the entire method) from another thread.

Andthis is the method its calling...

//In TableModel

publicsynchronizedint getAllRows()

{

int rows= getRowCount();

return rows;

}

I apparently need to lock the tablemodel and would need some kind of mutexes. How do I lock an object in Java?

thx!>

[1547 byte] By [CbbLea] at [2007-11-27 5:50:36]
# 1
Well, updates to Swing components should be done in the GUI event Thread. So the easiest solution is to follow this guide line.Read this article on [url http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html]Threads and Swing[/url].
camickra at 2007-7-12 15:38:17 > top of Java-index,Desktop,Core GUI APIs...
# 2
it doesn't matter if I use invokeLater() the tablemodel can still be accessed from another method. even though I think It should lock the model as it is within a synjchronized statement.
CbbLea at 2007-7-12 15:38:17 > top of Java-index,Desktop,Core GUI APIs...
# 3
Is there a way to lock the model? or another solution?
CbbLea at 2007-7-12 15:38:17 > top of Java-index,Desktop,Core GUI APIs...