Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Iteration over collections in Java is not thread safe, even if you are using one of the synchronized wrappers (<code>Collections.synchronizedMap(...)</code>):</p> <blockquote> <p>It is imperative that the user manually synchronize on the returned map when iterating over any of its collection views:</p> <pre><code>Map m = Collections.synchronizedMap(new HashMap()); ... Set s = m.keySet(); // Needn't be in synchronized block ... synchronized(m) { // Synchronizing on m, not s! Iterator i = s.iterator(); // Must be in synchronized block while (i.hasNext()) foo(i.next()); } </code></pre> </blockquote> <p><a href="http://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#synchronizedMap-java.util.Map-" rel="nofollow noreferrer">Java Collection Framework docs</a></p> <p>Other calls to synchronized collections are safe, as the wrapper classes surround them with <code>synchronized</code> blocks, which use the wrapper collection as their monitor:</p> <pre><code>public int size() { synchronized( this ) { return collection.size(); } } </code></pre> <p>with <code>collection</code> being the original collection. This works for all methods exposed by a collection/map, except for the iteration stuff.</p> <p>The key set of a map is made synchronized just the same way: the synchronized wrapper does not return the original key set at all. Instead, it returns a special synchronized wrapper of the collection's original key set. The same applies to the entry set and the value set.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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