src/share/classes/java/io/FileOutputStream.java

Print this page

        

*** 61,86 **** * True if the file is opened for append. */ private final boolean append; /** ! * The associated channel, initalized 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> --- 61,77 ---- * True if the file is opened for append. */ private final boolean append; /** ! * The associated channel, initialized lazily. */ private FileChannel channel; private final Object closeLock = new Object(); private volatile boolean closed = 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,366 **** * Decrement 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(); } } /** --- 344,357 ---- * Decrement 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(); } } /**
*** 422,445 **** 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(); --- 413,425 ----