Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>No real answers, but hopefully some useful information:</p> <p>The IdentityHashMap documentation (<a href="http://docs.oracle.com/javase/7/docs/api/java/util/IdentityHashMap.html" rel="nofollow">http://docs.oracle.com/javase/7/docs/api/java/util/IdentityHashMap.html</a>) states:</p> <blockquote> <p><strong>Note that this implementation is not synchronized</strong>. If multiple threads access an identity hash map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the Collections.synchronizedMap method. This is best done at creation time, to prevent accidental unsynchronized access to the map:</p> <p>Map m = Collections.synchronizedMap(new IdentityHashMap(...));</p> </blockquote> <p>So the Collections.synchronizedMap strategy sounds right, but this page (<a href="http://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html" rel="nofollow">http://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html</a>) makes me wonder about whether it will work since the methods are static:</p> <blockquote> <p><strong>Locks In Synchronized Methods</strong></p> <p>When a thread invokes a synchronized method, it automatically acquires the intrinsic lock for that method's object and releases it when the method returns. The lock release occurs even if the return was caused by an uncaught exception.</p> <p>You might wonder what happens when a static synchronized method is invoked, since a static method is associated with a class, not an object. In this case, the thread acquires the intrinsic lock for the Class object associated with the class. Thus access to class's static fields is controlled by a lock that's distinct from the lock for any instance of the class.</p> </blockquote> <p>Since those are static methods (even though the fields are not static), it's hard to tell if the Collections.synchronizedMap wrapper will really work to prevent a deadlock... My answer is that I have no answer!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload