src/share/classes/java/io/FileInputStream.java
Print this page
@@ -54,20 +54,10 @@
private FileChannel channel = null;
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 <code>FileInputStream</code> by
* opening a connection to an actual file,
* the file named by the path name <code>name</code>
* in the file system. A new <code>FileDescriptor</code>
@@ -317,14 +307,14 @@
* Decrement the 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();
}
}
/**
@@ -389,20 +379,9 @@
* @exception IOException if an I/O error occurs.
* @see java.io.FileInputStream#close()
*/
protected void finalize() throws IOException {
if ((fd != null) && (fd != FileDescriptor.in)) {
-
- /*
- * 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);
}
}
- }
}