Frage

Does Java's SocketChannel.read() method synchronize the output buffer?

In other words: is there a lock on the ByteBuffer argument passed to the read(ByteBuffer) method in java.nio.channels.SocketChannel (basically any channel). I need to know this so I don't have unnecessary synchronization blocks.

War es hilfreich?

Lösung

Java-Doc for SocketChannel says:

  • 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. The {@link
  • #connect connect} and {@link #finishConnect finishConnect} methods are
  • mutually synchronized against each other, and an attempt to initiate a read
  • or write operation while an invocation of one of these methods is in
  • progress will block until that invocation is complete.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top