Explanation of Illegalmonitorstateexception in Appium driver.wait newspaper

Source: Internet
Author: User
Tags appium

When writing Appium code, some people want to use the Wait method, written as: Driver.wait (), the result throws an exception: Illegalmonitorstateexception, see the Appium Client API documentation, The wait method is written like this:

Public final void Wait ()                throws Interruptedexception
Causes the current thread to wait until another thread invokes the notify()Method or the notifyAll()Method for this object. In other words, this method behaves exactly as if it simply performs the call wait(0).

The current thread must own this object ' s monitor. The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object ' s Mon Itor to wake up either through a call to the notify method or the notifyAll method. The thread then waits until it can re-obtain ownership of the monitor and resumes execution.

As in the one argument version, interrupts and spurious wakeups is possible, and this method should always being used in a l Oop:

     Synchronized (obj) {         while (<condition does not hold>)             obj.wait ();         ...//Perform action appropriate to condition     
This method, should only being called by a thread, is the owner of this object ' s monitor. See the notifyMethod for a description of the ways in which a thread can become the owner of a monitor.
illegalmonitorstateexception  -if the CU Rrent thread is not the owner of the object ' s monitor.
interruptedexception  -If any thread interrupted the current thread before or while the CU Rrent thread is waiting for a notification. the  interrupted status  of the current thread was cleared when this exception is thrown.
see Also:
notify () notifyall ()
illegalmonitorstateexception Exception Reason: If the current thread was not the owner of the OBJEC T ' s monitor, meaning that the current thread is not the owner of the object lock. The
 wait () method is to notify the current thread to wait and release the object lock, and to use the Wait method, the current thread needs to get to the driver object lock,  so the object lock needs to be acquired first. Use the Wait method in the synchronized block:

Synchronized (Driver)
driver.wait ();

This is possible, but you need to call the Notify method to wake the thread

Explanation of driver.wait in Appium illegalmonitorstateexception

Related Article

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.