fixed "Too many open files" - bug

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@174 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 20 years ago
parent 74eb21f62e
commit f8f8dd05db

@ -742,6 +742,12 @@ public class kelondroRecords {
this.entryFile = null; this.entryFile = null;
} }
public void finalize() {
try {
close();
} catch (IOException e) {}
}
protected static String[] line2args(String line) { protected static String[] line2args(String line) {
// parse the command line // parse the command line
if ((line == null) || (line.length() == 0)) return null; if ((line == null) || (line.length() == 0)) return null;

@ -165,14 +165,21 @@ public final class plasmaSearch {
// the map now holds the search results in order of number of hits per word // the map now holds the search results in order of number of hits per word
// we now must pairwise build up a conjunction of these sets // we now must pairwise build up a conjunction of these sets
String k = (String) map.firstKey(); // the smallest, which means, the one with the least entries String k = (String) map.firstKey(); // the smallest, which means, the one with the least entries
plasmaWordIndexEntity searchResult = (plasmaWordIndexEntity) map.remove(k); plasmaWordIndexEntity searchA, searchB, searchResult = (plasmaWordIndexEntity) map.remove(k);
while ((map.size() > 0) && (searchResult.size() > 0) && (time > 0)) { while ((map.size() > 0) && (searchResult.size() > 0) && (time > 0)) {
// take the first element of map which is a result and combine it with result // take the first element of map which is a result and combine it with result
k = (String) map.firstKey(); // the next smallest... k = (String) map.firstKey(); // the next smallest...
time -= (System.currentTimeMillis() - stamp); stamp = System.currentTimeMillis(); time -= (System.currentTimeMillis() - stamp); stamp = System.currentTimeMillis();
searchResult = joinConstructive(searchResult, (plasmaWordIndexEntity) map.remove(k), 2 * time / (map.size() + 1)); searchA = searchResult;
searchB = (plasmaWordIndexEntity) map.remove(k);
searchResult = joinConstructive(searchA, searchB, 2 * time / (map.size() + 1));
// close the input files/structures
if (searchA != searchResult) searchA.close();
if (searchB != searchResult) searchB.close();
} }
searchA = null; // free resources
searchB = null; // free resources
// in 'searchResult' is now the combined search result // in 'searchResult' is now the combined search result
if (searchResult.size() == 0) return new plasmaWordIndexEntity(null); if (searchResult.size() == 0) return new plasmaWordIndexEntity(null);
return searchResult; return searchResult;

@ -141,11 +141,17 @@ public class plasmaWordIndexEntity {
public void close() throws IOException { public void close() throws IOException {
if (theTmpMap == null) { if (theTmpMap == null) {
theIndex.close(); if (theIndex != null) theIndex.close();
theIndex = null; theIndex = null;
} else theTmpMap = null; } else theTmpMap = null;
} }
public void finalize() {
try {
close();
} catch (IOException e) {}
}
public boolean contains(String urlhash) throws IOException { public boolean contains(String urlhash) throws IOException {
if (theTmpMap == null) return (theIndex.get(urlhash.getBytes()) != null); else return (theTmpMap.containsKey(urlhash)); if (theTmpMap == null) return (theIndex.get(urlhash.getBytes()) != null); else return (theTmpMap.containsKey(urlhash));
} }

Loading…
Cancel
Save