The problem is that you use `if` instead of `while` before calling `wait()`. Due to spurious wakeups, threads can wake without a `notify()`, so you must re-check the condition in a loop to avoid incorrect behavior. This causes more than the intended number of threads to run simultaneously in your code. Using a `while` loop to guard `wait()` ensures the condition is truly met before proceeding. For a detailed explanation, see this article: