illegal monitor state Exception[soon as possible....]
netharam ram
Ranch Hand
Joined: Aug 09, 2001
Posts: 202
posted
0
code snippet: ------------- ..... ... int th=1; thgp=new ThreadGroup("File_hunter"); if(flag==0) { if(v_path.length>0) for(int i=0;i<v_path.length;i++) { if(v_path[i]!=null) { first=new Thread(thgp,this,("Thread"+th)); th++; System.out.println("v_path: "+v_path[i]); first.start(); } } if(v_ind!=1) { first=new Thread(thgp,this,("Master"+th)); th++; first.start(); } Thread tot=new Thread(thgp,this,"TotDel"); tot.start(); .................... ............... public void run() { String thname=Thread.currentThread().getName(); System.out.println("thread: "+thname); if(thname.startsWith("Master")) { if(v_ind==1) Dirlisting(v_path[i],chopt,0); else { Dirlisting(arg1,chopt,0); v_ind=1; } }//end of if. else if(thname.startsWith("To")) { try { wait(); }catch(Exception e){System.out.println(e);} System.out.println("Deleting"); totdeleted(); } } ...................... This is a piece of code,where I get an IllegalMonitorStateException.This is to display the files present in the given path including the subdirectories.Please help me to correct this as soon as possible. Happy middling with java. Netharam
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
posted
0
when you call wait(), the current object's wait() method is invoked, ie, you are calling this.wait(). It looks like the current object doesn't have a monitor associated with it. You haven't obtained a lock on the current object previous to calling wait() which you must do. Since you've only provided snippets of code it's really impossible to suggest how to fix your problem correctly, but one thing you can do is add the synchronized keyword to your run() method. This will get rid of the exception you are getting but may introduce deadlock or starvation, since now only one thread at a time may execute the run() method of this Runnable object, and your design may or may not work like this. [ March 07, 2002: Message edited by: Rob Ross ]
Rob
SCJP 1.4
subject: illegal monitor state Exception[soon as possible....]