I am cleaning up a legacy java code and I found following construct:
final class QuiteComplexClass {
private Object lock = new Object();
void aMethod() {
...
synchronized(lock) {
....
}
}
}
Is the special object for locking necessary here? What is difference when I used simple synchronized (this)
?
I think it might by useful when the class is publicly visible and somebody may call synchronized
on the class instance by mistake. But this class is package private so no external code can do that.