将那些IF语句转换为WHILE语句以获得所需的行为:
if (notifyAllExample.status != 2){ notifyAllExample.wait();}至
while (notifyAllExample.status != 2){ notifyAllExample.wait();}这将确保如果通知了线程,则在状态值达到预期值之前,它不会退出while循环。
另外,将其标记
status为volatile,这样线程就不会有本地副本。

将那些IF语句转换为WHILE语句以获得所需的行为:
if (notifyAllExample.status != 2){ notifyAllExample.wait();}至
while (notifyAllExample.status != 2){ notifyAllExample.wait();}这将确保如果通知了线程,则在状态值达到预期值之前,它不会退出while循环。
另外,将其标记
status为volatile,这样线程就不会有本地副本。