From 8ff76f8682c1b8a6e86438d788e7ce468a723834 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Tue, 10 Feb 2015 08:43:45 +0100 Subject: [PATCH] the cleanup process experienced a 100% CPU load situation and the loop did not terminate: Occurrences: 100 at java.util.HashMap$KeyIterator.next(HashMap.java:956) at net.yacy.cora.protocol.ConnectionInfo.cleanup(ConnectionInfo.java:300) at net.yacy.cora.protocol.ConnectionInfo.cleanUp(ConnectionInfo.java:293) at net.yacy.search.Switchboard.cleanupJob(Switchboard.java:2212) at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at net.yacy.kelondro.workflow.InstantBusyThread.job(InstantBusyThread.java:105) at net.yacy.kelondro.workflow.AbstractBusyThread.run(AbstractBusyThread.java:215) This tries to fix the problem; the problem should be monitored --- .../yacy/cora/protocol/ConnectionInfo.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/source/net/yacy/cora/protocol/ConnectionInfo.java b/source/net/yacy/cora/protocol/ConnectionInfo.java index 0e4af1e50..ce1784b54 100644 --- a/source/net/yacy/cora/protocol/ConnectionInfo.java +++ b/source/net/yacy/cora/protocol/ConnectionInfo.java @@ -26,12 +26,10 @@ package net.yacy.cora.protocol; import java.util.Collections; -import java.util.ConcurrentModificationException; import java.util.HashSet; import java.util.Iterator; import java.util.Set; - /** * Information about a connection * @@ -296,12 +294,17 @@ public class ConnectionInfo implements Comparable { private static void cleanup(final Set connectionSet) { final Iterator iter = connectionSet.iterator(); synchronized (iter) { - while (iter.hasNext()) try { - ConnectionInfo con = iter.next(); - if(con.getLifetime() > staleAfterMillis) { - connectionSet.remove(con); - } - } catch (ConcurrentModificationException e) {} + while (iter.hasNext()) { + ConnectionInfo con = null; + try { + con = iter.next(); + } catch (Throwable e) {break;} // this must break because otherwise there is danger that the loop does never terminates + try { + if (con.getLifetime() > staleAfterMillis) { + connectionSet.remove(con); + } + } catch (Throwable e) {continue;} + } } }