0

Please, consider the code below:

private boolean waitIfPaused() {
    AtomicBoolean pause = engine.getPause();
    if (pause.get()) {
        synchronized (engine.getPauseLock()) {
            if (pause.get()) {
                L.d(LOG_WAITING_FOR_RESUME, memoryCacheKey);
                try {
                    engine.getPauseLock().wait(); //here
                } catch (InterruptedException e) {
                    L.e(LOG_TASK_INTERRUPTED, memoryCacheKey);
                    return true;
                }
                L.d(LOG_RESUME_AFTER_PAUSE, memoryCacheKey);
            }
        }
    }
    return isTaskNotActual();
}

Findbugs plugin from Android Studio is complaining about the seventh line from this method, it says:

Wait not in loop This method contains a call to java.lang.Object.wait() which is not in a loop.  If the monitor is used for multiple conditions, the condition the caller intended to wait for might not be the one that actually occurred.

Someone knows how do I resolve this issue?

Gray
  • 115,027
  • 24
  • 293
  • 354
Erick
  • 147
  • 2
  • 7
  • 1
    Check answers for this question: [Why should wait() always be called inside a loop](http://stackoverflow.com/questions/1038007/why-should-wait-always-be-called-inside-a-loop). – free6om Mar 24 '16 at 00:49
  • I found [this answer](http://stackoverflow.com/a/1036763/6095334) by oxbow_lakes to be a good explanation. – Hervian Mar 24 '16 at 08:56

0 Answers0