While reading about synchronization, I came across "monitor pattern" to encapsulate mutable states.
The following is the sample code
public class MonitorLock {
private final Object myLock = new Object();
Widget widget;
void someMethod() {
synchronized(myLock) {
// Access or modify the state of widget
}
}
}
Is it better in any way to have a private lock instead of the intrinsic lock?
See Question&Answers more detail:os