Concurrency Anti-pattern Catalog for Java

Wrong lock or no lock bug anti-pattern

Problem: "A code segment is protected by a lock but other threads do not obtain the same lock instance when executing. Either these other threads do not obtain a lock at all or they obtain some lock other than the one used by the code segment" [FNU03].

Java example of the problem: ...

Context: Trying to protect access to operations involving shared data.

Solution: Identify all accesses to shared data and use the same lock object to protect these critical regions. This may involve added a new lock or replacing incorrect locks with the correct one.

Java example of the solution: ...

References:

[FNU03] E. Farchi, Y. Nir, and S. Ur, “Concurrent bug patterns and how to test them," in Proc. of the 1st International Workshop on Parallel and Distributed Systems: Testing and Debugging (PADTAD 2003), Apr. 2003.