The current thread in the thread is not the owner exception error

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.