2

I have an object (socketChannel) of java.nio.channels.SocketChannel opened.

And socketChannel.configureBlocking(false);

Is it safe:

  1. Write to it from one thread,
  2. Read from it in another thread,

at the same time?

Vitaly
  • 2,552
  • 2
  • 18
  • 21

1 Answers1

4

Yes, it's possible to have one thread writing to the SocketChannel, while one thread is reading from it.

From the Javadoc:

Socket channels are safe for use by multiple concurrent threads. They support concurrent reading and writing, though at most one thread may be reading and at most one thread may be writing at any given time.

https://docs.oracle.com/javase/8/docs/api/java/nio/channels/SocketChannel.html

ck1
  • 5,243
  • 1
  • 21
  • 25