Does AsynchronousSocketChannel.read(ByteBuffer) throw ShutdownChannelGroupException?
cowwoc
cowwoc at bbs.darktech.org
Thu Jun 25 07:18:13 PDT 2009
Alan Bateman wrote:
> Gili wrote:
>> AsynchronousSocketChannel.read(ByteBuffer) overrides
>> AsynchronousByteChannel.read(ByteBuffer). The latter has no concept of
>> ChannelGroups so it does not declare that the method may throw
>> ShutdownChannelGroupException. AsynchronousSocketChannel, on the other
>> hand,
>> declares that all I/O operation will throw
>> ShutdownChannelGroupException if
>> the channel group is shut down in the middle of an operation.
>>
>> There seems to be a conflict of specifications. Doesn't Design by
>> Contract
>> specify that a subclass may throw less exceptions but it may not throw
>> new
>> exceptions? I know that technically speaking all methods throw
>> RuntimeException but that's a little dirty. This exception does not
>> indicate
>> programming error and it is quite reasonable to expect that developers
>> will
>> want to catch it. At the very least,
>> AsynchronousSocketChannel.read(ByteBuffer)'s documentation should address
>> this more explicitly.
>>
> It's just an oversight that the ShutdownChannelGroupException is missing
> from the list of possible exceptions - I'll fix that thanks!
>
> As regards shutdown while there are I/O operations outstanding - it
> depends on if you use the shutdown or shutdownNow methods. The shutdown
> method does a graceful shutdown and does not impact the outstanding I/O
> operations. The shutdowNow method is to do a forceful shutdown and this
> is specified to close all open channels in the group. This causes all
> outstanding I/O operations to fail with AsynchronousCloseException.
I'm confused. If shutdownNow() causes outstanding operations to throw
AsynchronousCloseException when does ShutdownChannelGroupException get
thrown?
Thanks,
Gili
More information about the nio-discuss
mailing list