Why doesn't NIO provide an async-singlethreaded I/O?

Alan Bateman Alan.Bateman at oracle.com
Fri Oct 28 08:46:03 UTC 2016


On 28/10/2016 08:54, Brunoais wrote:

> Please read the quotes.
>
> They are from the thread "Re: Request/discussion: BufferedReader 
> reading using async API while providing sync API" from the mailing 
> list core-libs-dev at openjdk.java.net .
>
> The main question I have can be summarized to:
>
> Why isn't there (or was there) any non-block read-ahead I/O in java's 
> NIO (more question information in the quotes)?
If you looking to read ahead then a thread + synchronous I/O should work 
just fine, you don't need any additions to the Java SE APIs to do that. 
As always, do your performance tests to see if helps or not. I see Peter 
has provided some JMH examples, include dropping the file system cache 
between runs.

One other thing to add to your list to try is memory mapping the file 
with FileChannel::map and MappedByteBuffer. In particular, see if 
MappedByteBuffer::load helps.

(Aside from MappedByteBuffer::load, none of the existing APIs map to 
fadvise or madvise, in particular there is no way to advise that the 
access is expected to be sequential)

As regards AsynchronousFileChannel (which is the only non-blocking file 
I/O API in the platform) then it's not for sequential access. You can 
make it do sequential access of course but it will be a bit of work to 
do right.

-Alan


More information about the nio-dev mailing list