--- a/jdk/src/share/classes/java/io/FileOutputStream.java Sat Sep 10 21:30:20 2011 -0700
+++ b/jdk/src/share/classes/java/io/FileOutputStream.java Tue Sep 13 11:21:51 2011 +0100
@@ -63,21 +63,12 @@
private final boolean append;
/**
- * The associated channel, initalized lazily.
+ * The associated channel, initialized lazily.
*/
private FileChannel channel;
private final Object closeLock = new Object();
private volatile boolean closed = false;
- private static final ThreadLocal<Boolean> runningFinalize =
- new ThreadLocal<>();
-
- private static boolean isRunningFinalize() {
- Boolean val;
- if ((val = runningFinalize.get()) != null)
- return val.booleanValue();
- return false;
- }
/**
* Creates a file output stream to write to the file with the
@@ -355,10 +346,10 @@
int useCount = fd.decrementAndGetUseCount();
/*
- * If FileDescriptor is still in use by another stream, the finalizer
+ * If FileDescriptor is still in use by another stream, we
* will not close it.
*/
- if ((useCount <= 0) || !isRunningFinalize()) {
+ if (useCount <= 0) {
close0();
}
}
@@ -424,18 +415,7 @@
if (fd == FileDescriptor.out || fd == FileDescriptor.err) {
flush();
} else {
-
- /*
- * Finalizer should not release the FileDescriptor if another
- * stream is still using it. If the user directly invokes
- * close() then the FileDescriptor is also released.
- */
- runningFinalize.set(Boolean.TRUE);
- try {
close();
- } finally {
- runningFinalize.set(Boolean.FALSE);
- }
}
}
}