illegal monitor exception

import java.util.*;

import java.io.BufferedReader;

import java.io.DataInputStream;

import java.io.IOException;

import java.io.PrintWriter;

import java.net.Socket;

import java.net.UnknownHostException;

import javax.swing.table.DefaultTableModel;

public class tClient

{

static int port = 8084;

static String server = "192.168.0.89";

//int port = 6666;

//String server = "192.168.0.120";

static Socket socket ; //to create the client socket.

static PrintWriter output;// to send the data to the server.

static DataInputStream in;

static String line;

public Vector rows,columns;

public DefaultTableModel tabModel;

hashtable h=new hashtable();

int x=0;

//int lock;

public tClient(){

// *********CODE TO CREATE CONNECTION WITH THE SERVER. ************ /////////////

//this.id=id;

//this.sym=sym;

//this.rqtp=sym;

/*try {

socket = new Socket(server, port); //to create a socket to connect to the server.

System.out.println("Connected with server: " +socket.getInetAddress() + " on port :" + socket.getPort());

} catch (UnknownHostException e) { //Exception thrown when the Host is not Found.

System.out.println("Unknown Host Exception:" + e);

} catch (IOException e) {

System.out.println("IO Exception :" + e);

}*/

/* String ID[]=id;

String SMY[]=sym;

String RQTP[]=rqtp;*/

synchronized(h){

(new Thread(){

public void run()

{

//System.out.println(">>>>>>>in RUN");

try {

socket = new Socket(server, port); //to create a socket to connect to the server.

//System.out.println(">>>>>>>in TRY");

//input = new BufferedReader(new InputStreamReader(System.in)); // BufferedReader input is used to accept the data from the user.

output = new PrintWriter(socket.getOutputStream(),true); // PrintWriter output to write the data to the server

//System.out.println(output);

//System.out.println(">>>>>>>After Line");

in = new DataInputStream(socket.getInputStream());

line = "<111><EURGBP A1-FX,EURNOK A1-FX,IBM,MSFT,CA,DELL><Forex><Customer>";

//output.println("<90901><EUR/USD,AUD/USD,GBP/USD><Forex Market>");

output.write(line);

output.flush();

// ********* END OF PRINT WRITER BLOCK . *************///////////////////

//hashtable2 hh2=new hashtable2();

//Test1 ob1 = new Test1(hh2);

String symbol=null,last=null,lastSize=null,bid=null,bidSize=null,ask=null,askSize=null;

//line = in.readUTF(); // wait for the server to send a line of text.

// line = in.readLine(); // wait for the server to send a line of text.

String value=in.readLine().trim();

System.out.println("Message from Server : " + value+"\n");

StringTokenizer st = new StringTokenizer(value,"<,>");

while (st.hasMoreTokens()) // make sure there is stuff to get

{

int i=0;

symbol = st.nextElement().toString();

last = st.nextElement().toString();

lastSize= st.nextElement().toString();

bid=st.nextElement().toString();

bidSize=st.nextElement().toString();

ask=st.nextElement().toString();

askSize=st.nextElement().toString();

h.a1.add(new String(symbol));

h.a2.add(new String(last));

h.a3.add(new String(lastSize));

h.a4.add(new String(bid));

h.a5.add(new String(bidSize));

h.a6.add(new String(ask));

h.a7.add(new String(askSize));

h.ht.put(h.a1.get(i),symbol);

h.ht1.put(h.a2.get(i),last);

h.ht2.put(h.a3.get(i),lastSize);

h.ht3.put(h.a4.get(i),bid);

h.ht4.put(h.a5.get(i),bidSize);

h.ht5.put(h.a6.get(i),ask);

h.ht6.put(h.a7.get(i),askSize);

System.out.println(h.ht.get(h.a1.get(i)));

System.out.println(h.ht1.get(h.a2.get(i)));

System.out.println(h.ht2.get(h.a3.get(i)));

System.out.println(h.ht3.get(h.a4.get(i)));

System.out.println(h.ht4.get(h.a5.get(i)));

System.out.println(h.ht5.get(h.a6.get(i)));

System.out.println(h.ht6.get(h.a7.get(i)));

i++;

h.wait(2000L);

}

}

catch (Exception e)

{

System.out.println(e);

}}}).start();}

synchronized(h){

(new Thread(){

public void run()

{

execute();

h.notify();

}

public void execute()

{

for(int i=0;i<h.s1.length;i++)

{

System.out.println("IN Run");

//hashtable2 hh2=new hashtable2();

String symbol=null,last=null,lastSize=null,bid=null,bidSize=null,ask=null,askSize=null;

System.out.println("1ST");

//System.out.println(h.a1.get(0));

symbol=(String)(h.ht.get(h.a1.get(i)));

System.out.println("2ND");

last=(String)(h.ht1.get(h.a2.get(i)));

lastSize=(String)(h.ht2.get(h.a3.get(i)));

System.out.println("3RD");

bid=(String)(h.ht3.get(h.a4.get(i)));

bidSize=(String)(h.ht4.get(h.a5.get(i)));

ask=(String)(h.ht5.get(h.a6.get(i)));

askSize=(String)(h.ht6.get(h.a7.get(i)));

System.out.println(symbol);

addRow(symbol,last,lastSize);

}

}

private void addRow(String id,String symbol,String RequestType) //Add Row

{

System.out.println("Enetered to addRow");

Vector r=new Vector();

r=createBlankElement(id,symbol,RequestType);

rows.addElement(r);

//testDataFrameob.table.addNotify();

//testDataFrameob.table.repaint();

// testDataFrameob.table.revalidate();

//testDataFrameob.tabModel.getModel().fireTableDataChanged();

tabModel.fireTableDataChanged();

//testDataFrameob.tabModel.fireTableRowsInserted(0,1);

System.out.println("Row Added");

/* Refresh RefreshOb = new Refresh();

RefreshOb.setVisible(true);

RefreshOb.dispose();*/

//JOptionPane.showMessageDialog(null,"Row Added");

}

public Vector createBlankElement(String id,String symbol,String RequestType) {

Vector t = new Vector();

t.addElement(id);

t.addElement(symbol);

t.addElement(RequestType);

return t;

}

}).start();}

try {

socket.close();//to close the client socket.

} catch (IOException e) {

System.out.println(e);

}

}

}

this is the code of my main program in which i have two threads in the first thread i am trying to store the value in the Hashtable by hashtable class and then wants ti wait and invoke the other available thread to read data from the hastable but i am getting the illegal monitor errow current thread does not own the thread .all the datas i am receiving from e-signals plz help me

thanks in advance>

[6908 byte] By [jamesgoslina] at [2007-11-27 7:27:56]
# 1
synchronized(h) {h.wait(2000);}andsynchronized(h) {h.notify();}
BinaryDigita at 2007-7-12 19:08:11 > top of Java-index,Core,Core APIs...
# 2
hi frnd i think u have not seen the code carefully i am alrady doing the same sujjested by you plz analyse it carefully and sujjest me the solution i m in great need.thanks in advance
jamesgoslina at 2007-7-12 19:08:11 > top of Java-index,Core,Core APIs...
# 3
There are so many of undefined symbols in your posted code. Please post a small demo code that is generally compilable, runnable and could reproduce your problem. See: http://homepage1.nifty.com/algafield/sscce.html and http://www.yoda.arachsys.com/java/newsgroups.html
hiwaa at 2007-7-12 19:08:11 > top of Java-index,Core,Core APIs...
# 4

> hi frnd i think u have not seen the code carefully i

> am alrady doing the same sujjested by you plz analyse

> it carefully and sujjest me the solution i m in great

> need.

>

>

>

> thanks in advance

Forgive me, but I can't see where you're synchronizing the wait call. And your notify call is not synchronized correctly, you're only synchronizing the creation of the thread. Instead of this:

synchronized(h) {

new Thread() {

public void run() {

h.notify();

}

}.start();

}

You need this:

new Thread() {

public void run() {

synchronized(h) {

h.notify();

}

}

}.start();

It would also help for you to repost the code using code tags.

BinaryDigita at 2007-7-12 19:08:11 > top of Java-index,Core,Core APIs...