appium中driver.wait报IllegalMonitorStateException的解释
在写appium代码的时候,有的人想使用wait方法,写成:driver.wait(),结果抛出异常:IllegalMonitorStateException,看了appium client的api文档,关于wait方法是这么写的:
public final void wait()
throws InterruptedException
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的解释的更多相关文章
- 【转】Appium 中截取 element 图片作为对比,判断对比结果
其实在https://github.com/gb112211/Adb-For-Test 里面有一个截取element进行对比的方法,但是在使用appium时是无法使用的,因为其用到了uiautomat ...
- 解决MyEclipse中的js报错的小方法
今天,下了个模版,但是导进去的时候发现js会报错.看了下其他都没有错误.而有一个js报错误,请原谅我有点红色强迫症,不能留一点红色 . 错误如下:Syntax error on token " ...
- 转OSGchina中,array老大的名词解释
转OSGchina中,array老大的名词解释 转自:http://ydwcowboy.blog.163.com/blog/static/25849015200983518395/ osg:: Cle ...
- 关于Entity Framework中的Attached报错相关解决方案的总结
关于Entity Framework中的Attached报错的问题,我这里分为以下几种类型,每种类型我都给出相应的解决方案,希望能给大家带来一些的帮助,当然作为读者的您如果觉得有不同的意见或更好的方法 ...
- 关于Entity Framework中的Attached报错的完美解决方案终极版
之前发表过一篇文章题为<关于Entity Framework中的Attached报错的完美解决方案>,那篇文章确实能解决单个实体在进行更新.删除时Attached的报错,注意我这里说的单个 ...
- Eclipse中启动tomcat报错:A child container failed during start
我真的很崩溃,先是workspace崩了,费了好久重建的workspace,然后建立了一个小demo项目,tomcat中启动却报错,挑选其中比较重要的2条信息如下: A child container ...
- MyEclipse8.6中提交SVN报错
上周五(11月27日)的时候,从TortoiseSVN提交项目报错,然后直接从MyEclipse中检出来,修改后提交同样报错. MyEclipse8.6中提交SVN报错,错误提示如下: commit ...
- 嵌入式中的 *(volatile unsigned int *)0x500 解释
C语言中*(volatile unsigned int *)0x500的解释: 如下: (unsigned int *)0x500:将地址0x500强制转化为int型指针*(unsigned int ...
- VC++中几种字符标志的解释
VC++中几种字符标志的解释 LPSTR = char * LPCSTR = const char * LPWSTR = wchar_t * LPCWSTR = const wchar_t * LPO ...
随机推荐
- 类型:.net;问题:asp.net window验证;结果:细说ASP.NET Windows身份认证
细说ASP.NET Windows身份认证 阅读目录 开始 认识ASP.NET Windows身份认证 访问 Active Directory 在ASP.NET中访问Active Directory ...
- scrapy(1)安装
用的是python3.6 pip install -i https://pypi.douban.com/simple/ scrapy scrapy startproject Article scrap ...
- 部署和调优 1.1 nfs部署和优化-2
更改共享目录文件默认的所有者和所属组 已知道客户端有个user11用户 cat /etc/passwd user11:x:501:501::/home/user11:/bin/bash 服务端打开 v ...
- 【知识碎片】Net项目经验积累
后台传JSON到js报错 MVC控制器传json到前端JS"变为" 导致JS报错 重点是一定要在@ViewBag.typeJson两边加双引号,并且后台用 编码前台解码 ViewB ...
- wamp配置小细节
1. 问题:在安装后,把phpMyadmin改密码后,再次登陆会提示出错.访问被拒绝. 原因:这是因为WampServer设置了直接登陆. 解法:修改config.inc.php文件中$cfg['Se ...
- C++对二进制文件的操作实例
有5个学生的数据,要求: (1)将它们存放到磁盘文件中: (2)将磁盘文件中的第1,3,5个学生数据读入程序,并显示出来: (3)将第三个学生的数据修改后存回磁盘文件中的原有位置: (4)从磁盘文件读 ...
- java中是如何解决编码问题的,比如char类型的对象是如何存储的呢?
主题句:每个编码形式将字符从字符集转换为编码数据. 说白了一个代码点就是一个Unicode字符.代码单元就是代码点的集合. 字符视图 要了解字符集标准,您必须能区分三种不同的字符视图: 字符集(字符的 ...
- 9.Delegate类
Concepts 不像MVC模式,Model/View模式并没有单独用来处理事件和用户交互的组件(controller).通常,视图负责向用户呈现模型中的数据,并处理用户的输入.有时,为了让 ...
- 动态tab页
1.前台代码 <%-- builed by manage.aspx.cmt [ver:2015.25.26] at 2015-06-26 15:25:42 --%> <%@ Pag ...
- Entity Framework Tutorial Basics(25):Delete Single Entity
Delete Entity using DBContext in Disconnected Scenario: We used the Entry() method of DbContext to m ...