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) ?
Both nw.wait() and nw.sleep() cause the current thread to pause execution, not the thread on which you you call them. There is no way to cause a different thread to pause.
The nw.wait() call is used to pause the current thread's execution for a period of time or until another thread notifies it to continue. It is used for inter thread communication and must be inside a synchronized block where you synchronize on the same object you call wait on (wait is a method in the Object interface, not Thread, so any and every Object can be used for synchronization and wait()ing.)
Thread#sleep() is a static method in Thread which pauses the current thread of execution for a fixed period of time.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: getting java.lang.IllegalMonitorStateException: current thread not owner .