You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2010/08/11 21:42:33 UTC

svn commit: r984554 - /wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java

Author: mgrigorov
Date: Wed Aug 11 19:42:32 2010
New Revision: 984554

URL: http://svn.apache.org/viewvc?rev=984554&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/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java

Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java?rev=984554&r1=984553&r2=984554&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java Wed Aug 11 19:42:32 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;
@@ -84,7 +83,8 @@ public class ModificationWatcher impleme
 	}
 
 	/**
-	 * @see org.apache.wicket.util.watch.IModificationWatcher#add(org.apache.wicket.util.watch.IModifiable, org.apache.wicket.util.listener.IChangeListener)
+	 * @see org.apache.wicket.util.watch.IModificationWatcher#add(org.apache.wicket.util.watch.IModifiable,
+	 *      org.apache.wicket.util.listener.IChangeListener)
 	 */
 	public final boolean add(final IModifiable modifiable, final IChangeListener listener)
 	{
@@ -147,13 +147,10 @@ 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();
-				while (iter.hasNext())
+				final Iterator<Entry> itor = modifiableToEntry.values().iterator();
+				while (itor.hasNext())
 				{
-					final Entry entry = iter.next();
+					final Entry entry = itor.next();
 
 					// If the modifiable has been modified after the last known
 					// modification time