src/share/classes/java/io/FileOutputStream.java
Print this page
@@ -61,26 +61,17 @@
* True if the file is opened for append.
*/
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
* specified name. A new <code>FileDescriptor</code> object is
* created to represent this file connection.
* <p>
@@ -353,14 +344,14 @@
* Decrement FD use count associated with this stream
*/
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();
}
}
/**
@@ -422,24 +413,13 @@
protected void finalize() throws IOException {
if (fd != null) {
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);
}
}
- }
}
private native void close0() throws IOException;
private static native void initIDs();