illegal java monitor exception

hi all,

i am making an application in which i am receiving live data from from server and i am storing that data into hashtable through one thread then i am reading data from the same hashtable through another thread and wans to display upon applet now the problem is that i am getting

Exception in thread "Thread-4" java.lang.IllegalMonitorStateException: current thread not owner

at java.lang.Object.notify(Native Method)

at Test1$2.execute(Test1.java:102)

at Test1$2.run(Test1.java:73)etting exception

[542 byte] By [jamesgoslina] at [2007-11-27 6:51:13]
# 1
You need to hold the lock for the object you're waiting/notifying. Search the forum. This has been answered many times before.
cooper6a at 2007-7-12 18:25:31 > top of Java-index,Core,Core APIs...
# 2

I believe in your current code the synchronized/wait/notify mechanism is decentralized and dispersed among accessor objects of the required data. You should centralize it for the peace of your life.

/* pseudo code */

public class MyDataStore{

private Hashtable data;

public synchronized Boo getData(Object key){

while (data is empty){

wait();

}

return data.get(key); // may return null

}

// etc.

}

hiwaa at 2007-7-12 18:25:31 > top of Java-index,Core,Core APIs...