Today, my friend ask me to review some code of him, his code will encounter some unexpected error. He’s very confused and worried. After digging into the code, I found the problem.
Here’s the code slice :
private boolean done;
private Message[] messages;
… …
synchronized(this) {
if(!done || messages ==null) {
// 1
try {
wait();
// 2
} catch (InterruptedException e) {
e.printStackTrace();
}
…
dispatchMessage(messages);
// […]
Popularity: 18%





