*) Trying to solve "Too many open files bug"

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@601 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
theli 20 years ago
parent 34790acf02
commit b67f008eb8

@ -85,9 +85,16 @@ public class kelondroFileRA extends kelondroAbstractRA implements kelondroRA {
public void close() throws IOException { public void close() throws IOException {
RAFile.close(); RAFile.close();
RAFile = null;
} }
protected void finalize() throws Throwable {
if (RAFile != null) {
this.close();
}
super.finalize();
}
// some static tools // some static tools
public static void writeProperties(File f, Properties props, String comment) throws IOException { public static void writeProperties(File f, Properties props, String comment) throws IOException {
File fp = f.getParentFile(); File fp = f.getParentFile();

@ -205,8 +205,19 @@ public class kelondroNIOFileRA extends kelondroAbstractRA implements kelondroRA
bufferTail.force(); bufferTail.force();
System.out.println("wrote " + name + " tail"); System.out.println("wrote " + name + " tail");
} }
RAChannel.close(); RAChannel.close();
RAFile.close(); RAChannel = null;
RAFile.close();
RAFile = null;
}
protected void finalize() throws Throwable {
if (RAChannel != null) {
try {RAChannel.close();}catch(Exception e){}
}
if (RAFile != null) {
try {RAFile.close();}catch(Exception e){}
}
} }

@ -264,34 +264,39 @@ public class kelondroStack extends kelondroRecords {
} }
public int imp(File file, String separator) throws IOException { public int imp(File file, String separator) throws IOException {
// imports a value-separated file, returns number of records that have been read // imports a value-separated file, returns number of records that have been read
RandomAccessFile f = new RandomAccessFile(file,"r"); RandomAccessFile f = null;
String s; try {
StringTokenizer st; f = new RandomAccessFile(file,"r");
int recs = 0; String s;
byte[][] buffer = new byte[columns()][]; StringTokenizer st;
int c; int recs = 0;
int line = 0; byte[][] buffer = new byte[columns()][];
while ((s = f.readLine()) != null) { int c;
s = s.trim(); int line = 0;
line++; while ((s = f.readLine()) != null) {
if ((s.length() > 0) && (!(s.startsWith("#")))) { s = s.trim();
st = new StringTokenizer(s, separator); line++;
// buffer the entry if ((s.length() > 0) && (!(s.startsWith("#")))) {
c = 0; st = new StringTokenizer(s, separator);
while ((c < columns()) && (st.hasMoreTokens())) { // buffer the entry
buffer[c++] = st.nextToken().trim().getBytes(); c = 0;
} while ((c < columns()) && (st.hasMoreTokens())) {
if ((st.hasMoreTokens()) || (c != columns())) { buffer[c++] = st.nextToken().trim().getBytes();
System.err.println("inapropriate number of entries in line " + line); }
} else { if ((st.hasMoreTokens()) || (c != columns())) {
push(buffer); System.err.println("inapropriate number of entries in line " + line);
recs++; } else {
} push(buffer);
recs++;
} }
}
return recs; }
}
return recs;
} finally {
if (f!=null) try{f.close();}catch(Exception e){}
}
} }
public String hp(Handle h) { public String hp(Handle h) {
@ -349,17 +354,23 @@ public class kelondroStack extends kelondroRecords {
ret = (i + " records imported").getBytes(); ret = (i + " records imported").getBytes();
} else if (args[0].equals("-s")) { } else if (args[0].equals("-s")) {
String db = args[2]; String db = args[2];
BufferedReader f = new BufferedReader(new FileReader(args[1])); BufferedReader f = null;
String m; try {
while (true) { f = new BufferedReader(new FileReader(args[1]));
m = f.readLine();
if (m == null) break; String m;
if ((m.length() > 1) && (!m.startsWith("#"))) { while (true) {
m = m + " " + db; m = f.readLine();
cmd(line2args(m)); if (m == null) break;
} if ((m.length() > 1) && (!m.startsWith("#"))) {
} m = m + " " + db;
ret = null; cmd(line2args(m));
}
}
ret = null;
} finally {
if (f != null) try {f.close();}catch(Exception e) {}
}
} else if (args[0].equals("-g")) { } else if (args[0].equals("-g")) {
kelondroStack fm = new kelondroStack(new File(args[2]), 0x100000); kelondroStack fm = new kelondroStack(new File(args[2]), 0x100000);
byte[][] ret2 = fm.pop(Integer.parseInt(args[1])); byte[][] ret2 = fm.pop(Integer.parseInt(args[1]));

@ -1216,17 +1216,22 @@ public class kelondroTree extends kelondroRecords implements Comparator {
ret = (i + " records imported").getBytes(); ret = (i + " records imported").getBytes();
} else if (args[0].equals("-s")) { } else if (args[0].equals("-s")) {
String db = args[2]; String db = args[2];
BufferedReader f = new BufferedReader(new FileReader(args[1])); BufferedReader f = null;
String m; try {
while (true) { f = new BufferedReader(new FileReader(args[1]));
m = f.readLine(); String m;
if (m == null) break; while (true) {
if ((m.length() > 1) && (!m.startsWith("#"))) { m = f.readLine();
m = m + " " + db; if (m == null) break;
cmd(line2args(m)); if ((m.length() > 1) && (!m.startsWith("#"))) {
} m = m + " " + db;
} cmd(line2args(m));
ret = null; }
}
ret = null;
} finally {
if (f != null) try {f.close();}catch(Exception e){}
}
} else if (args[0].equals("-g")) { } else if (args[0].equals("-g")) {
kelondroTree fm = new kelondroTree(new File(args[1]), 0x100000); kelondroTree fm = new kelondroTree(new File(args[1]), 0x100000);
byte[][] ret2 = fm.get(args[2].getBytes()); byte[][] ret2 = fm.get(args[2].getBytes());

Loading…
Cancel
Save