I am new to multithreading .
I am getting Exception in
thread "main" java.lang.IllegalMonitorStateException: current thread not owner .
below is my code .
NewTask nw = new NewTask(1);
nw.start();
try{
nw.wait(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
I want to wait thread nw for few seconds after starting .
I changed wait(5000) to nw.sleep(5000); then it doesn't give any problem . by watching current thread not owner it seems nw is not the thread that is going to wait !!
I wonder whether wait(long) will pause the executing thread or the Thread of which object is called.
Can any body explain me .. when to use wait(long) & when to use sleep(long) ?
Thanks in advance .