From cf739edc2e7da62f00b62a05ce61bc57f68f6e68 Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 7 Aug 2009 12:11:22 +0000 Subject: [PATCH] fix for possible deadlock, see http://forum.yacy-websuche.de/viewtopic.php?p=17017#p17017 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6252 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/crawler/Balancer.java | 38 ++++++++++++-------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/source/de/anomic/crawler/Balancer.java b/source/de/anomic/crawler/Balancer.java index 9db2b1828..ab6ca8664 100644 --- a/source/de/anomic/crawler/Balancer.java +++ b/source/de/anomic/crawler/Balancer.java @@ -116,22 +116,24 @@ public class Balancer { return new Request(entry); } - public synchronized int removeAllByProfileHandle(final String profileHandle, final long timeout) throws IOException { + public int removeAllByProfileHandle(final String profileHandle, final long timeout) throws IOException { // removes all entries with a specific profile hash. // this may last some time // returns number of deletions // first find a list of url hashes that shall be deleted - final Iterator i = urlFileIndex.rows(); final HashSet urlHashes = new HashSet(); - Row.Entry rowEntry; - Request crawlEntry; final long terminate = (timeout > 0) ? System.currentTimeMillis() + timeout : Long.MAX_VALUE; - while (i.hasNext() && (System.currentTimeMillis() < terminate)) { - rowEntry = i.next(); - crawlEntry = new Request(rowEntry); - if (crawlEntry.profileHandle().equals(profileHandle)) { - urlHashes.add(crawlEntry.url().hash()); + synchronized (this) { + final Iterator i = urlFileIndex.rows(); + Row.Entry rowEntry; + Request crawlEntry; + while (i.hasNext() && (System.currentTimeMillis() < terminate)) { + rowEntry = i.next(); + crawlEntry = new Request(rowEntry); + if (crawlEntry.profileHandle().equals(profileHandle)) { + urlHashes.add(crawlEntry.url().hash()); + } } } @@ -242,10 +244,8 @@ public class Balancer { if (domainList == null) { // create new list domainList = new LinkedList(); - synchronized (domainStacks) { - domainList.add(hash); - domainStacks.put(dom, domainList); - } + domainList.add(hash); + domainStacks.put(dom, domainList); } else { // extend existent domain list if (domainList.size() < maxstacksize) domainList.addLast(hash); @@ -268,13 +268,11 @@ public class Balancer { private String nextFromDelayed() { if (this.delayed.size() == 0) return null; - synchronized (this.delayed) { - if (this.delayed.size() == 0) return null; - Long first = this.delayed.firstKey(); - if (first.longValue() < System.currentTimeMillis()) { - return this.delayed.remove(first); - } - } + if (this.delayed.size() == 0) return null; + Long first = this.delayed.firstKey(); + if (first.longValue() < System.currentTimeMillis()) { + return this.delayed.remove(first); + } return null; }