Author: mgrigorov
Date: Wed Aug 11 19:45:18 2010
New Revision: 984557

URL: http://svn.apache.org/viewvc?rev=984557&view=rev
Log:
WICKET-2964 Improve the code that uses copy-list-on-iterate pattern

Remove the copying of the map's values before iterating over them.
>From java.util.concurrent.ConcurrentHashMap.values() javadoc:

The view's returned <tt>iterator</tt> is a "weakly consistent" iterator that
will never throw {...@link java.util.ConcurrentModificationException},
and guarantees to traverse elements as they existed upon
construction of the iterator, and may (but is not guaranteed to)
reflect any modifications subsequent to construction.

It seems the copying was there from the days before "modifiableToEntry" became 
ConcurrentHashMap


Modified:
    
wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java

Modified: 
wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java?rev=984557&r1=984556&r2=984557&view=diff
==============================================================================
--- 
wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java
 (original)
+++ 
wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java
 Wed Aug 11 19:45:18 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.wicket.util.watch;
 
-import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
@@ -148,10 +147,7 @@ public class ModificationWatcher impleme
                {
                        public void run(final Logger log)
                        {
-                               // Iterate over a copy of the list of entries 
to avoid concurrent modification
-                               // problems without the associated liveness 
issues of holding a lock while
-                               // potentially polling file times!
-                               Iterator<Entry> iter = new 
ArrayList<Entry>(modifiableToEntry.values()).iterator();
+                               Iterator<Entry> iter = 
modifiableToEntry.values().iterator();
                                while (iter.hasNext())
                                {
                                        final Entry entry = iter.next();


Reply via email to