Java.lang.illegalmonitorstateexception While Executing Asynctask For Multiple Times
I refer this solution to run AsyncTask for multiple time. But I am getting following error when i call tryAgain.signal(); E/AndroidRuntime: FATAL EXCEPTION: main Process: com.weba
Solution 1:
You should acquire a lock associated with the Condition before call signal.
publicvoidrunAgain() {
// Call this to request data from the server againlock.lock();
try {
tryAgain.signal();
} finally {
lock.unlock();
}
}
The solution You referenced has a own bug.
Below is copied from Android API Reference.
Implementation Considerations
An implementation may (and typically does) require that the current thread hold the lock associated with this Condition when this method is called. Implementations must document this precondition and any actions taken if the lock is not held. Typically, an exception such as IllegalMonitorStateException will be thrown.
If job should be executed multiple times, Thread, Handler or Service can be a better choice than AsyncTask.
Post a Comment for "Java.lang.illegalmonitorstateexception While Executing Asynctask For Multiple Times"