...
This code does not violate CON06CON11-J. Do not synchronize on a collection view if the backing collection is accessible, because while it does synchronize on a collection view (the synchronizedList
), the backing collection is inaccessible, and therefore cannot be modified by any code.
...
This compliant solution does not use Collections.synchronizedMap()
because locking on the unsynchronized map provides sufficient thread-safety for this application. CON06CON11-J. Do not synchronize on a collection view if the backing collection is accessible provides more information about synchronizing on synchronizedMap
objects.
...
Wiki Markup |
---|
\[[API 06|AA. Java References#API 06]\] \[[JavaThreads 04|AA. Java References#JavaThreads 04]\] Section 8.2, "Synchronization and Collection Classes" \[[Goetz 06|AA. Java References#Goetz 06]\] Section 4.4.1, "Client-side Locking," Section 5.2.1, "ConcurrentHashMap" \[[Lee 09|AA. Java References#Lee 09]\] "Map & Compound Operation" |
...
CON06CON11-J. Do not synchronize on a collection view if the backing collection is accessible 11. Concurrency (CON) CON01-J. Ensure visibility of shared references to immutable objects