News for hackers. Stuff that matters.
Re:Async file IO in Java is not truly async [Resource, Tech ... by twic on Monday January 08, 2024 @04:24PM (#38918373)
> I doubt, as that would break any FileChannel.write(ByteBuffer) that expects the buffer to be consumed (remaining()==0)

You can't expect that with AsynchronousFileChannel::write at the moment, though, because the buffer is consumed on a background thread. As the docs say [1]:

> Buffers are not safe for use by multiple concurrent threads so care should be taken to not access the buffer until the operation has completed.

And as the article says, on Windows, these writes are "truly" async at the OS level, so portable code already needs to deal with that.

[1] https://docs.oracle.com/en/java/javase/17/docs/api/java.base...

There are no comments on this comment yet.