在写appium代码的时候,有的人想使用wait方法,写成:driver.wait(),结果抛出异常:IllegalMonitorStateException,看了appium client的api文档,关于wait方法是这么写的:

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 monitor to wake up either through a call to the notify method or thenotifyAll 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 are possible, and this method should always be used in a loop:

     synchronized (obj) {
while (<condition does not hold>)
obj.wait();
... // Perform action appropriate to condition
}

This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.

Throws:
IllegalMonitorStateException - if the current thread is not the owner of the object's monitor.
InterruptedException - if any thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.
See Also:
notify()notifyAll()
IllegalMonitorStateException异常原因:if the current thread is not the owner of the object's monitor,意思就是当前线程不是该对象锁的所有者。
 wait()方法是通知当前线程等待并释放对象锁,要想用wait方法,当前线程需要获取到driver对象锁, 所以需要先获取到对象锁,使用把wait方法放到synchronized块中:

synchronized (driver)
{
driver.wait();
}

这样就可以了,但是需要调用notify方法唤醒线程

appium中driver.wait报IllegalMonitorStateException的解释的更多相关文章

  1. 【转】Appium 中截取 element 图片作为对比,判断对比结果

    其实在https://github.com/gb112211/Adb-For-Test 里面有一个截取element进行对比的方法,但是在使用appium时是无法使用的,因为其用到了uiautomat ...

  2. 解决MyEclipse中的js报错的小方法

    今天,下了个模版,但是导进去的时候发现js会报错.看了下其他都没有错误.而有一个js报错误,请原谅我有点红色强迫症,不能留一点红色 . 错误如下:Syntax error on token " ...

  3. 转OSGchina中,array老大的名词解释

    转OSGchina中,array老大的名词解释 转自:http://ydwcowboy.blog.163.com/blog/static/25849015200983518395/ osg:: Cle ...

  4. 关于Entity Framework中的Attached报错相关解决方案的总结

    关于Entity Framework中的Attached报错的问题,我这里分为以下几种类型,每种类型我都给出相应的解决方案,希望能给大家带来一些的帮助,当然作为读者的您如果觉得有不同的意见或更好的方法 ...

  5. 关于Entity Framework中的Attached报错的完美解决方案终极版

    之前发表过一篇文章题为<关于Entity Framework中的Attached报错的完美解决方案>,那篇文章确实能解决单个实体在进行更新.删除时Attached的报错,注意我这里说的单个 ...

  6. Eclipse中启动tomcat报错:A child container failed during start

    我真的很崩溃,先是workspace崩了,费了好久重建的workspace,然后建立了一个小demo项目,tomcat中启动却报错,挑选其中比较重要的2条信息如下: A child container ...

  7. MyEclipse8.6中提交SVN报错

    上周五(11月27日)的时候,从TortoiseSVN提交项目报错,然后直接从MyEclipse中检出来,修改后提交同样报错. MyEclipse8.6中提交SVN报错,错误提示如下: commit ...

  8. 嵌入式中的 *(volatile unsigned int *)0x500 解释

    C语言中*(volatile unsigned int *)0x500的解释: 如下: (unsigned int *)0x500:将地址0x500强制转化为int型指针*(unsigned int ...

  9. VC++中几种字符标志的解释

    VC++中几种字符标志的解释 LPSTR = char * LPCSTR = const char * LPWSTR = wchar_t * LPCWSTR = const wchar_t * LPO ...

随机推荐

  1. 框架之 hibernate之关联关系映射

    案例:完成CRM的联系人的保存操作 需求分析 1. 因为客户和联系人是一对多的关系,在有客户的情况下,完成联系人的添加保存操作 技术分析之Hibernate的关联关系映射之一对多映射(重点) 1. J ...

  2. C++面向对象类的实例题目四

    题目描述: 以面向对象的概念设计一个类,此类包含3个私有数据:unlead.lead(无铅汽油和有铅汽油)以及total(当天总收入,无铅汽油的价格是17元/升,有铅汽油的加个是16元/升),请以构造 ...

  3. ZROI2018提高day5t3

    传送门 分析我们可以根据性质将这个序列构造成一个环:0,a[1~n],0,a[n~1] 这中间的0是为了起间隔作用的. 我们又知道b[i]=a[i-1]^a[i+1] c[i]=b[i-1]^b[i+ ...

  4. cakephp目录结构

  5. 1.初学c++,比较困惑的问题。

    1.c++是一门实用的语言吗? c++是一个实用的工具,它很有用. 在工业软件世界中,c++被视为坚实和成熟的主流工具.它具有广泛的行业支持和好批. 2.面向对象编程在c++中的作用? 我们要开发一个 ...

  6. UVa 1204 Fun Game (状压DP)

    题意:有一些小孩(至少两个)围成一圈,有 n 轮游戏,每一轮从某个小孩开始往左或者往右伟手帕,拿到手帕写上自己的性别(B,G),然后以后相同方向给下一个. 然后在某个小孩结束,给出 n 轮手帕上的序列 ...

  7. Java 分析模板方法设计模型

    http://www.cnblogs.com/maowang1991/archive/2013/04/15/3023236.html //父类 abstract class Operate{ prot ...

  8. [译]Javascript中的switch语句

    本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...

  9. Bugly升级应用集成指南

    1.配置 app/build.gradle android { defaultConfig { ndk { //设置支持的SO库架构 abiFilters 'armeabi' //, 'x86', ' ...

  10. drools规则引擎笔记(二)

    规则引擎版本,drools6.5.0 final eclipse:Neon JDK1.8 今天主要是在规则的when部分加入了多个fact对象. 对于working memory存在多个fact的情形 ...