Why does this break statement break not work?
- by Roman
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.
The interesting thing is that it happens not all the time. Sometimes my program works fine, sometimes the above described problem happens.