...
Using a private lock may only be achieved with block synchronization, as static method synchronization always uses the intrinsic lock of the object's class. However, block synchronization is also preferred over method synchronization, because it is easy to move operations out of the synchronized block when they might take a long time and they are not truly a critical section.
Exceptions
EX1: Classes A Class may violate this guideline, if they :
- it sufficiently
...
- documents that callers must not pass
...
- objects of this class to untrusted code.
...
- trusted callers must not use
...
- any untrusted classes that violate
...
- this guideline directly or indirectly,
- finally, this class must document proper usage of its intrinsic lock, and when external classes may use the intrinsic lock, and when they may not.
Risk Assessment
Exposing the class object to untrusted code can result in denial-of-service.
...