This is a part of my program.
Thread rcv_thread = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("getmsg");
while (true) {
/*try {
Thread.sleep(0);
} catch (InterruptedException e) {
e.printStackTrace();
}*/
if (!getmsg.isEmpty() && socket.isConnected()) {
System.out.println("handle");
getmsg_ = getmsg.get(0).split(";");
if (socket.getInetAddress().toString()
.equals("/" + getmsg_[0])) {
PW.println(getmsg_[2] + " sent from"
+ getmsg_[1]);
getmsg.remove(0);
}
}
}
}
});
rcv_thread.start();
It is really so strange.The program never runs in the range of while(true){}
while I comment the range of try{}catch{}
But if I cancel the comment in the range of try{}catch{}
The loop will successfully runs and runs in the range of while(true){}
This is my problem. Sorry for my poor English.