...
One technique for preventing this vulnerability is the private lock object idiom [Bloch 2001]. This idiom uses the intrinsic lock associated with the instance of a private final java.lang.Object
declared within the class instead of the intrinsic lock of the object itself. This idiom requires the use of synchronized blocks within the classâs methods rather than the use of synchronized methods. Lock contention between the classâs methods and those of a hostile class becomes impossible because the hostile class cannot access the private final lock object.
...
This noncompliant code example also violates rule OBJ01-J. Declare data members as private and provide accessible wrapper methodsLimit accessibility of fields.
Compliant Solution (Private Final Lock Object)
...
Bibliography
Item 52. Document Thread Safety |
...