harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Regis <xu.re...@gmail.com>
Subject Re: [classlib][nio]Is selector.close() blocking or not?
Date Tue, 13 Jan 2009 06:19:27 GMT
I'm not expert, following comments are just my understanding :)

Hui Ding wrote:
> Hi Experts,
> I am writing an application with NIO and Selector and found a strange
> issue that if I call "Selector.close()" while a thread is being
> blocked on that Selector(By calling "Selector.select()"), the call to
> "close()" will block indefinitely until "Selector.select()" returns.
> It's said in the Javadoc of selector.close() that: "If a thread is
> currently blocked in one of this selector's selection methods then it
> is interrupted as if by invoking the selector's wakeup method". So I
> guess under no circumstances should Select.close() block, right?

I think Select.close() should be non-block, and will interrupt blocked 
select operations, as you tested with Sun's JDK, it's reasonable.

> However I came across another topic about the concurrency of Selector:
> "The selection operations synchronize on the selector itself, on the
> key set, and on the selected-key set, in that order.
> The close method synchronizes on the selector and all three key sets
> in the same order as in a selection operation." If it is true that
> Selector.select() and Selector.close() both synchronize on the
> selector itself, I think Selector.close() will block if other threads
> are blocked on Selector.select().
It just says the synchronize order in close method, but didn't mention 
the whole close method should be protected by the three locks, right?
Maybe we could invoke wakeup() method, and then get these locks.

> 
> Now I am confused about which one is the correct behavior of
> Selector.close(), blocking or not?
answered above
> 
> BTW. I gave it a try on a Desktop PC with SUN JDK and Harmony JDK, seems
> with SUN JDK, Selector.close() will never block while with Harmony
> JDK, if another thread is being blocked on Selector.select(),
> Selector.close will block until select() returns. Is this a bug with
> Harmony JDK or not?
> 
I believe it's Harmony's bug.

I'll try to investigate this problem.

-- 
Best Regards,
Regis.

Mime
View raw message