AsynchronousChannel.close()

Gili cowwoc at bbs.darktech.org
Thu Jun 25 07:15:33 PDT 2009


Okay, this is what I thought at first. What threw me off is... how can
multiple threads be waiting on the result of the same I/O operation?

Thanks,
Gili


Alan Bateman wrote:
> 
> Gili wrote:
>> Hi,
>>
>> The Javadoc for AsynchronousChannel reads "Where the cancel method is
>> invoked with the mayInterruptIfRunning parameter set to true then the I/O
>> operation may be interrupted by closing the channel. In that case all
>> threads waiting on the result of the I/O operation throw
>> CancellationException and any other I/O operations outstanding on the
>> channel complete with the exception AsynchronousCloseException."
>>
>> I don't understand the last part. Are you implying that all Futures get
>> CancellationException whereas all CompletionHandlers get
>> AsynchronousCloseException? Or did you mean something else?
>>
>> The paragraph makes it seem as if Futures that are not actively being
>> waited
>> on will throw AsynchronousCloseException when get() is eventually
>> invoked.
>> This sounds rather difficult from an implementation point of view. Please
>> clarify.
>>   
> The spec allows a forceful cancel (mayInterruptIfRunning parameter set 
> to true) to be implemented as an asynchronous close. This will cause 
> "other" I/O operations outstanding on the channel to fail with 
> AsynchronousCloseException. So for example, suppose you forcefully 
> cancel a write while there is read outstanding. All threads waiting on 
> the result of the write will throw CancellationException. Assuming the 
> implementation closes the channel, then it will cause the read to fail 
> with an AsynchronousCloseException. If the read was initiated specifying 
> a completion handler, then the completion handler's failed method will 
> be invoked with the exception (AsynchronousCloseException). 
> Alternatively, if the read was initiated returning a Future then any 
> threads waiting on the read result will throw ExecutionException with 
> AsynchronousCloseException as the cause. Does that help?
> 
> -Alan.
> 
> 

-- 
View this message in context: http://n2.nabble.com/AsynchronousChannel.close%28%29-tp3152177p3155293.html
Sent from the nio-discuss mailing list archive at Nabble.com.




More information about the nio-discuss mailing list