Archive for December, 2004

Using spin lock in your code

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%


Creative Commons License
This work is licensed under a Creative Commons License.

一天就好象是这短暂的一生,一生它只是无尽的路上短暂的一天