I have done like below But it is not executing run once we invoke it is stopped after printing Two ;I don't know the basics of thread, package asia.test; public class FaultModelRefresher extends Thread{
public FaultModelRefresher(){ System.out.println("One"); Thread t=new Thread(); t.start(); System.out.println("Two"); } public void run(){ int i=0; System.out.println("Three"); try{ while(true){ wait(10000); System.out.println("Yes = "+i); i++; } }catch(Exception e){ System.out.println("Exception in FaultModelRefresher = "+e); }
while calling from another class like this FaultModelRefresher fm=new FaultModelRefresher(); fm.start(); getting an exception java.lang.IllegalMonitorStateException: current thread not owner Can anybody tell i want just keep on executing the run method with a wait option.
A good thing i am just getting ready for the SCJP. You get an IllegalMonitorStateException because you are calling wait outside a synchronized block. If you use wait() you have to first have a lock on it so for example: