Recent Posts
Archives

PostHeaderIcon Sonar / Synchronization on interned XYZ could lead to deadlock

How to fix the Sonar’s following report?
[java]Multithreaded correctness – Synchronization on interned String could lead to deadlock [/java]

Replace lock on String with a lock on an immutable and/or non-serializable object, ie a simple Object.
Eg:
Replace:
[java] synchronized ("myString") {…}[/java]
With:
[java] synchronized (myObject) {…}[/java]

Leave a Reply