Should java/nio/channels/spi/ be synchronized ?

Sean Chou zhouyx at
Tue Dec 4 18:47:24 PST 2012

A small problem I'm still checking. So the closeLock is just to make sure
the channel is closed only once, is that right?

On Tue, Dec 4, 2012 at 10:38 PM, Chris Hegarty <chris.hegarty at>wrote:

> On 12/04/2012 02:13 PM, Alan Bateman wrote:
>> On 04/12/2012 10:53, Sean Chou wrote:
>>> Hello,
>>> I found AbstractInterruptibleChannel.**close() is synchronized using
>>> closeLock, but isOpen() is not synchronized. Javadoc of isOpen() says
>>> "Returns: true if, and only if, this channel is open". I want to know
>>> if isOpen() method is designed not to synchronize with closeLock ?
>>> Because in close() method the closeLock embraces "open = false;" and "
>>> implCloseChannel(); " , which looks like the open variable should
>>> always reflect the real state.
>> What problem are you running into? I see anything wrong with isOpen and
>> it would create a lot of issues if it were to synchronize on closeLock.
> I also don't see any issue. Since 'open' is volatile, visibility is
> guaranteed. Yes, this is racy code, but that's the nature of asynchronous
> close/interrupt.
> -Chris.
>> -Alan

Best Regards,
Sean Chou
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the nio-dev mailing list