< prev index next >

src/java.base/share/classes/java/io/FileInputStream.java

Print this page
rev 15897 : 8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
Reviewed-by: alanb, shade, plevart

*** 24,34 **** */ package java.io; import java.nio.channels.FileChannel; - import java.util.concurrent.atomic.AtomicBoolean; import sun.nio.ch.FileChannelImpl; /** * A <code>FileInputStream</code> obtains input bytes --- 24,33 ----
*** 58,68 **** */ private final String path; private volatile FileChannel channel; ! private final AtomicBoolean closed = new AtomicBoolean(false); /** * Creates a <code>FileInputStream</code> by * opening a connection to an actual file, * the file named by the path name <code>name</code> --- 57,69 ---- */ private final String path; private volatile FileChannel channel; ! private final Object closeLock = new Object(); ! ! private volatile boolean closed; /** * Creates a <code>FileInputStream</code> by * opening a connection to an actual file, * the file named by the path name <code>name</code>
*** 311,324 **** * * @revised 1.4 * @spec JSR-51 */ public void close() throws IOException { ! if (!closed.compareAndSet(false, true)) { ! // if compareAndSet() returns false closed was already true return; } FileChannel fc = channel; if (fc != null) { fc.close(); } --- 312,330 ---- * * @revised 1.4 * @spec JSR-51 */ public void close() throws IOException { ! if (closed) { ! return; ! } ! synchronized (closeLock) { ! if (closed) { return; } + closed = true; + } FileChannel fc = channel; if (fc != null) { fc.close(); }
*** 368,378 **** if (fc == null) { synchronized (this) { fc = this.channel; if (fc == null) { this.channel = fc = FileChannelImpl.open(fd, path, true, false, this); ! if (closed.get()) { try { fc.close(); } catch (IOException ioe) { throw new InternalError(ioe); // should not happen } --- 374,384 ---- if (fc == null) { synchronized (this) { fc = this.channel; if (fc == null) { this.channel = fc = FileChannelImpl.open(fd, path, true, false, this); ! if (closed) { try { fc.close(); } catch (IOException ioe) { throw new InternalError(ioe); // should not happen }
< prev index next >