JDK-4509080 : (ch) Streams inhibit concurrent reading & writing
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.0,1.4.1,6u20
  • Priority: P4
  • Status: Resolved
  • Resolution: Won't Fix
  • OS:
    generic,solaris_8,windows_nt,windows_2000 generic,solaris_8,windows_nt,windows_2000
  • CPU: generic,x86,sparc
  • Submitted: 2001-10-01
  • Updated: 2019-05-25
  • Resolved: 2013-08-22
Related Reports
Duplicate :  
Duplicate :  
Description
For tracking purposes :-

1. java.nio.channels.Channels provides support for interoperation of
stream classes with channels classes. However there may be concurrency
as both Channels.newInputStream(sc).read() and
Channels.newOutputStream(sc).write() synchronize on the blockingLock.
Thus a thread blocked on read will cause another thread wishing to
write to block.

2. As a SocketChannel is a ReadableByteChannel it may be worth 
updating the specification of Channels.newInputStream to indicate
that the reads on the InputStream do not timeout if 
sc.socket().setSoTimeout() is called to specify a 
timeout (or maybe there should timeout?).

3. Similiar to item 1 the new SocketAdaptor prohibits concurrent
reader & writes threads -- eg: thread blocked on 
sc.socket().getInputStream().read() will cause another thread
to block in sc.socket().getOutputStream().write(). The issue
gets a more complicated with read timeouts as the channel is
temporarily put into non-blocking mode to support the timeout.
Thus if the blockingLock issue is resolved we need to ensure
that 'write' supports the blocking semantics irrespective of
the blocking mode of the channel.

Comments
The socket adaptors were partly re-implemented as part of JDK-8222774 and so are no longer constrained to use the blockingLock. As a result, concurrent reading and writing with the socket adpator is possible. In fact, the changes mean that adaptors work the same as legacy Socket with the exception that blocking I/O operations are interruptible (interrupting a thread blocked on the Socket will close the underlying channel).
25-05-2019

This was a design bug, one blockingLock is insufficient to support all adaptors. This has no impact on anyone using SocketChannel, it only impacts those that are using the socket adpators to integrate with code that uses classic java.net.Socket.
26-02-2018