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
pull/1/head
orbiter 16 years ago
parent 6354b5e447
commit cf739edc2e

@ -116,22 +116,24 @@ public class Balancer {
return new Request(entry); 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. // removes all entries with a specific profile hash.
// this may last some time // this may last some time
// returns number of deletions // returns number of deletions
// first find a list of url hashes that shall be deleted // first find a list of url hashes that shall be deleted
final Iterator<Row.Entry> i = urlFileIndex.rows();
final HashSet<String> urlHashes = new HashSet<String>(); final HashSet<String> urlHashes = new HashSet<String>();
Row.Entry rowEntry;
Request crawlEntry;
final long terminate = (timeout > 0) ? System.currentTimeMillis() + timeout : Long.MAX_VALUE; final long terminate = (timeout > 0) ? System.currentTimeMillis() + timeout : Long.MAX_VALUE;
while (i.hasNext() && (System.currentTimeMillis() < terminate)) { synchronized (this) {
rowEntry = i.next(); final Iterator<Row.Entry> i = urlFileIndex.rows();
crawlEntry = new Request(rowEntry); Row.Entry rowEntry;
if (crawlEntry.profileHandle().equals(profileHandle)) { Request crawlEntry;
urlHashes.add(crawlEntry.url().hash()); 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) { if (domainList == null) {
// create new list // create new list
domainList = new LinkedList<String>(); domainList = new LinkedList<String>();
synchronized (domainStacks) { domainList.add(hash);
domainList.add(hash); domainStacks.put(dom, domainList);
domainStacks.put(dom, domainList);
}
} else { } else {
// extend existent domain list // extend existent domain list
if (domainList.size() < maxstacksize) domainList.addLast(hash); if (domainList.size() < maxstacksize) domainList.addLast(hash);
@ -268,13 +268,11 @@ public class Balancer {
private String nextFromDelayed() { private String nextFromDelayed() {
if (this.delayed.size() == 0) return null; if (this.delayed.size() == 0) return null;
synchronized (this.delayed) { if (this.delayed.size() == 0) return null;
if (this.delayed.size() == 0) return null; Long first = this.delayed.firstKey();
Long first = this.delayed.firstKey(); if (first.longValue() < System.currentTimeMillis()) {
if (first.longValue() < System.currentTimeMillis()) { return this.delayed.remove(first);
return this.delayed.remove(first); }
}
}
return null; return null;
} }

Loading…
Cancel
Save