From f8f8dd05dba00cf448243347d01357e2d9312d45 Mon Sep 17 00:00:00 2001 From: orbiter Date: Wed, 25 May 2005 11:35:01 +0000 Subject: [PATCH] fixed "Too many open files" - bug git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@174 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/kelondro/kelondroRecords.java | 6 ++++++ source/de/anomic/plasma/plasmaSearch.java | 13 ++++++++++--- source/de/anomic/plasma/plasmaWordIndexEntity.java | 8 +++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/source/de/anomic/kelondro/kelondroRecords.java b/source/de/anomic/kelondro/kelondroRecords.java index 8057d53b3..e6f118f03 100644 --- a/source/de/anomic/kelondro/kelondroRecords.java +++ b/source/de/anomic/kelondro/kelondroRecords.java @@ -742,6 +742,12 @@ public class kelondroRecords { this.entryFile = null; } + public void finalize() { + try { + close(); + } catch (IOException e) {} + } + protected static String[] line2args(String line) { // parse the command line if ((line == null) || (line.length() == 0)) return null; diff --git a/source/de/anomic/plasma/plasmaSearch.java b/source/de/anomic/plasma/plasmaSearch.java index 123f6598a..2ce2928e1 100644 --- a/source/de/anomic/plasma/plasmaSearch.java +++ b/source/de/anomic/plasma/plasmaSearch.java @@ -165,14 +165,21 @@ public final class plasmaSearch { // 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 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)) { // take the first element of map which is a result and combine it with result k = (String) map.firstKey(); // the next smallest... 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 if (searchResult.size() == 0) return new plasmaWordIndexEntity(null); return searchResult; diff --git a/source/de/anomic/plasma/plasmaWordIndexEntity.java b/source/de/anomic/plasma/plasmaWordIndexEntity.java index 4c9388e33..0ff1e80a1 100644 --- a/source/de/anomic/plasma/plasmaWordIndexEntity.java +++ b/source/de/anomic/plasma/plasmaWordIndexEntity.java @@ -141,11 +141,17 @@ public class plasmaWordIndexEntity { public void close() throws IOException { if (theTmpMap == null) { - theIndex.close(); + if (theIndex != null) theIndex.close(); theIndex = null; } else theTmpMap = null; } + public void finalize() { + try { + close(); + } catch (IOException e) {} + } + public boolean contains(String urlhash) throws IOException { if (theTmpMap == null) return (theIndex.get(urlhash.getBytes()) != null); else return (theTmpMap.containsKey(urlhash)); }