InputStream/OutputStream concurrency guarantees

Alan Bateman alan.bateman at oracle.com
Mon Oct 27 17:02:23 UTC 2025



On 27/10/2025 11:47, Pavel Rappo wrote:
> The specification of the read/write methods, their classes, and the
> package is silent on multithreading. In which case you should always
> assume that the methods are **not** thread-safe.
Right, although there are some APIs that do specify that input or output 
streams are safe for used by concurrent threads, e.g. the input/output 
streams returned by the Channels class that support interop between 
channels and input/output streams.

Another more subtle aspect to the topic is async close. With many 
input/output streams it doesn't make any sense to attempt to use them 
from concurrent threads but async close when there is a blocker 
read/writer is something that has to be supported in some cases.

In any access, I read Florian's mail as asking something else. I read 
the mail as concurrent access to the byte[], e.g. someone flipping bytes 
while someone is calling write.

-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20251027/4eb3b28c/attachment-0001.htm>


More information about the core-libs-dev mailing list