0

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.

3
  • Why don't you look in the source code?
    – Michael-O
    Dec 6, 2012 at 20:02
  • Wait, really? Since when does Oracle publish their source code?
    – Jon
    Dec 6, 2012 at 20:05
  • Since Java has gone open source?!
    – Michael-O
    Dec 6, 2012 at 20:06

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.