System.IO.File
in .NET and .NET Core has a family of Read...Async()
methods, all of which return either Task<byte[]>
or Task<string>
(Task<T>
is the .NET's equivalent of Java's Future<T>
).
This looks largely equivalent to AsynchronousFileChannel
APIs (which either consume a CompletionHandler
or return a Future
), with one major difference.
AsynchronousFileChannel
uses a managed background thread to perform asynchronous I/O (the thread may be provided either by the default thread pool (sun.nio.ch.ThreadPool
) or by theExecutorService
explicitly specified during channel creation).FileStream
implementation in .NET, on the other hand, passesFileOptions.Asynchronous
flag to the underlying operating system (see also Synchronous and Asynchronous I/O), doesn't spawn any managed background threads and uses what is called an Overlapped I/O.
Questions:
- Is there any (existing or planned) File I/O API in Java which would use Overlapped I/O on Windows and POSIX AIO on Unices? Update: Windows-specific Java runtime features
sun.nio.ch.WindowsAsynchronousFileChannelImpl
which is exactly an abstraction layer on top of Overlapped I/O. - Are there any plans to provide
java.nio.channels.SelectableChannel
implementations for File I/O? If no, what are the technical limitations?
epoll
on Linux, available since 2.6, as well as kernel-accelerated AIO,O_DIRECT
and friends? How aboutkqueue
on Mac OS X and the BSDs? Next, I/O Completion Ports (IOCP) are available not only on Windows, but also on AIX and Solaris 10+ (though the interfaces are of course different). Finally, why not use the POSIX AIO which may be not that advanced as any of the above APIs but much more common? – Chane