Some common methods of Multithreading: Wait (), wait (Long), notify (), Notifyall (), etc.
These methods are instance methods of the current class,
Wait () is the thread that holds the lock on the object to release the lock;
Wait (long) is the time that the thread holding the object lock is freed for a long (milliseconds) and the lock is acquired again, and wait () and wait (0) are equivalent;
Notify () is a thread that is waiting for the lock on the object, and if more than one thread is waiting, the thread being awakened is determined by the JVM;
Notifyall is the thread that wakes up all waiting for the object lock.
and the Notifyall () method should be preferred, because waking up all threads makes it easier for the JVM to find the most suitable thread to be awakened than to wake up a thread.
For the above method, it is only available in the current thread, otherwise the run-time error java.lang.IllegalMonitorStateException:current thread not owner.
From the implementation point of view to analyze:
When a thread calls the Wait () method, it needs to be placed in a synchronization segment, which should be used before the call
1synchroed (This) {
2 thread.wait ();
3
4}
5
Otherwise, the "Java.lang.IllegalMonitorStateException:current Thread not owner" exception will appear.
Transferred from: http://www.blogjava.net/crazycy/archive/2006/10/08/73896.html
The current thread in the thread is not the owner exception error