我有以下代码:
public void post(String message) {
final String mess = message;
(new Thread() {
public void run() {
while (true) {
try {
if (status.equals("serviceResolved")) {
output.println(mess);
Game.log.fine("The following message was successfully sent: " + mess);
break;
} else {
try {Thread.sleep(1000);} catch (InterruptedException ie) {}
}
} catch (NullPointerException e) {
try {Thread.sleep(1000);} catch (InterruptedException ie) {}
}
}
}
}).start();
}
在我的日志文件中,我发现很多这样的行:
The following message was successfully sent: blablabla
The following message was successfully sent: blablabla
The following message was successfully sent: blablabla
The following message was successfully sent: blablabla
我的程序没有响应。
在我看来,该break
命令不起作用。这可能是什么原因。
有趣的是,它并非总是发生。有时我的程序运行良好,有时会发生上述问题。