...
An alternative is to use block synchronization by defining an internal private final lock object in the extending class. This is the preferred choice when untrusted code can obtain the intrinsic lock of the class object (CON04-J. Use the private lock object idiom instead of intrinsic synchronizationa class's intrinsic locking mechanism).
| Code Block | ||
|---|---|---|
| ||
// ...
public class SynchronizedSubclass extends SynchronizedBase {
private final Object lock = new Object();
public void doSomething() {
synchronized(lock) {
// ...
}
}
}
|
...