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: 2018-02-26
  • Resolved: 2013-08-22
Related Reports
Duplicate :  
Duplicate :  
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.

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.