java threading, what's wrong with my code

theamericanidol

New Member
I want to update a Object in another thread, and then access it in current thread:\[code\] public Object getValueAt(final int rowIndex, int columnIndex) { data.getRealm().exec(new Runnable(){ @Override public void run() { System.out.println("Object at " + rowIndex + " in WritableList is " + data.get(rowIndex)); object = (DOModel) data.get(rowIndex); System.out.println(object); object.notify(); } });// suspend current thread try { synchronized (object){ object.wait(); } } catch (InterruptedException e) { e.printStackTrace(); } if(columnIndex == 0){ System.out.println(object); return object.getId(); } }\[/code\]but when I run my code a java.lang.IllegalMonitorStateException occurs.I changed my code, see comments in code:Edit --------------------------------\[code\] public Object getValueAt(final int rowIndex, int columnIndex) { data.getRealm().exec(new Runnable(){ @Override public void run() { System.out.println("Object at " + rowIndex + " in WritableList is " + data.get(rowIndex)); object = (DOModel) data.get(rowIndex); synchronized(object){ object.notify(); } } }); try { synchronized (object){ object.wait(); } } catch (InterruptedException e) { e.printStackTrace(); }// this line below is never executed. System.out.println(object); if(columnIndex == 0){ return object.getId(); } }\[/code\]
 
Top