相关疑难解决方法(0)

为什么这个break语句不起作用?

我有以下代码:

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();
}
Run Code Online (Sandbox Code Playgroud)

在我的日志文件中,我发现了很多像这样的行:

The following message was successfully sent: blablabla
The following message was successfully sent: blablabla
The following …
Run Code Online (Sandbox Code Playgroud)

java loops break

6
推荐指数
1
解决办法
2135
查看次数

标签 统计

break ×1

java ×1

loops ×1