src/share/classes/java/io/FileInputStream.java
Print this page
*** 54,73 ****
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>
--- 54,63 ----
*** 317,330 ****
* Decrement the FD use count associated with this stream
*/
int useCount = fd.decrementAndGetUseCount();
/*
! * If FileDescriptor is still in use by another stream, the finalizer
* will not close it.
*/
! if ((useCount <= 0) || !isRunningFinalize()) {
close0();
}
}
/**
--- 307,320 ----
* Decrement the FD use count associated with this stream
*/
int useCount = fd.decrementAndGetUseCount();
/*
! * If FileDescriptor is still in use by another stream, we
* will not close it.
*/
! if (useCount <= 0) {
close0();
}
}
/**
*** 389,408 ****
* @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);
}
}
- }
}
--- 379,387 ----