exception - Testng throwing java.lang.IllegalMonitorStateException -
i using testng
automation framework. when line of code below executed in test case results in java.lang.illegalmonitorstateexception
.
can suggest how fix this? method should wait 2 minutes.
{ timeunit.minutes.wait(2); }
as javadoc says:
the current thread must own object's monitor.
in other words, can call object.wait
on object within synchronized
method or block locking object waiting on.
you should using thread.sleep(...)
or timeunit.sleep(...)
. read respective javadocs understand units of parameters.
if use wait
, usage incorrect reason well. though looks waiting 2 minutes, actually waiting 2 milliseconds ... because calling object
implementation of wait
. if wanted use timeunit
version, code need this:
synchronized lock { timeunit.minutes.timedwait(lock, 2); }
where lock
suitable (private, unshared) object using locking.
also, beware if notifies lock / locked object, wait(...)
call wake early. makes wait
, inappropriate solution in if not cases want wait given period time.
Comments
Post a Comment