作者:鄙人fisher_779 | 来源:互联网 | 2023-07-24 13:09
Ihavethefollowingcode:我有以下代码:publicvoidpost(Stringmessage){finalStringmessmessa
I have the following code:
我有以下代码:
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();
}
In my log file I find a lot of lines like this:
在我的日志文件中,我发现了很多像这样的行:
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
And my program is not responding.
我的程序没有响应。
It seems to me that the break
command does not work. What can be a possible reason for that.
在我看来,break命令不起作用。可能的原因是什么?
The interesting thing is that it happens not all the time. Sometimes my program works fine, sometimes the above described problem happens.
有趣的是,它并非总是发生。有时我的程序运行正常,有时会出现上述问题。
5 个解决方案