Hi all whenever I use the synchronized statement, I often use this pattern:
private static Object lock = new Object();
public void F(){
//..
synchronized (lock){
//..
}
//..
}
However, in the source of java.lang.Reference
, I see that they employ this pattern instead:
static private class Lock { };
private static Lock lock = new Lock();
public void run() {
//..
synchronized(lock){
//..
}
//..
}
I was wondering what's the benefit of declaring a new class Lock (which basically extends Object and do nothing else) ?
Or rather, why didn't they simply use private static Lock lock = new Object();
?