我有以下代码:
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命令不起作用.可能的原因是什么?
有趣的是,它并非总是发生.有时我的程序工作正常,有时会出现上述问题.