Single-Thread Wakeup

ID

java.prefer_notifyall

Severity

high

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Java

Tags

concurrency, reliability

Description

Reports calls to notify(), which wakes only one thread waiting on the monitor.

Rationale

notify() wakes an arbitrary single thread out of however many are waiting on the object’s monitor. If more than one thread can be waiting at the same time, there is no guarantee the woken thread is the one whose condition just became true, and the other waiters stay asleep indefinitely. notifyAll() wakes every waiter so each can re-check its own condition.

// Bad - only one waiter wakes up, chosen arbitrarily
synchronized (lock) {
    lock.notify();
}

Remediation

Call notifyAll() unless the code can prove at most one thread is ever waiting on this monitor.

// Good
synchronized (lock) {
    lock.notifyAll();
}

© 2026 Xygeni. All rights reserved