remove FSIndexOutput finalizer, move FSIndexInput finalizer to it's Descriptor: LUCENE-750

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@488722 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2006-12-19 16:31:06 +00:00
parent 19ba76b0d4
commit 30c8ce4f10
2 changed files with 32 additions and 34 deletions

View File

@ -327,6 +327,10 @@ Optimizations
to the List of clauses and replaced the internal synchronized Vector
with an unsynchronized List. (Yonik Seeley)
16. LUCENE-750: Remove finalizers from FSIndexOutput and move the
FSIndexInput finalizer to the actual file so all clones don't
register a new finalizer. (Yonik Seeley)
Test Cases
1. Added TestTermScorer.java (Grant Ingersoll)
2. Added TestWindowsMMap.java (Benson Margulies via Mike McCandless)

View File

@ -496,26 +496,40 @@ public class FSDirectory extends Directory {
class FSIndexInput extends BufferedIndexInput {
private class Descriptor extends RandomAccessFile {
public long position;
public Descriptor(File file, String mode) throws IOException {
super(file, mode);
}
}
private Descriptor file = null;
private static class Descriptor extends RandomAccessFile {
// remember if the file is open, so that we don't try to close it
// more than once
private boolean isOpen;
long position;
final long length;
public Descriptor(File file, String mode) throws IOException {
super(file, mode);
isOpen=true;
length=length();
}
public void close() throws IOException {
if (isOpen) {
isOpen=false;
super.close();
}
}
protected void finalize() throws Throwable {
try {
close();
} finally {
super.finalize();
}
}
}
private final Descriptor file;
boolean isClone;
private long length;
public FSIndexInput(File path) throws IOException {
file = new Descriptor(path, "r");
isOpen = true;
length = file.length();
}
/** IndexInput methods */
@ -539,27 +553,15 @@ class FSIndexInput extends BufferedIndexInput {
}
public void close() throws IOException {
// only close the file if this is not a clone and the
// file has not been closed yet
if (!isClone && isOpen) {
file.close();
isOpen = false;
}
// only close the file if this is not a clone
if (!isClone) file.close();
}
protected void seekInternal(long position) {
}
public long length() {
return length;
}
protected void finalize() throws Throwable {
try {
close(); // close the file
} finally {
super.finalize();
}
return file.length;
}
public Object clone() {
@ -611,12 +613,4 @@ class FSIndexOutput extends BufferedIndexOutput {
return file.length();
}
protected void finalize() throws Throwable {
try {
close(); // close the file
} finally {
super.finalize();
}
}
}