about Selector.select is block ,but jstack thread is runnable

Bernd Eckenfels ecki at zusammenkunft.net
Thu May 8 15:09:38 UTC 2014


All Code which blocks inside native methods on native objects (like blocking read on file descriptors or sockets, as well as waits on selectors are not blocking with Java concurrency features and therefore (a bit missleading) in RUNABLE state.

Greetings
Bernd

> Am 08.05.2014 um 14:55 schrieb fuyou <fuyou001 at gmail.com>:
> 
> the jstack:
> 
> NETTYSERVER-WORKER-19-thread-4" prio=10 tid=0x00000000136d3800
> nid=0x75dc runnable [0x00000000499be000]
>   java.lang.Thread.State: RUNNABLE
>        at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
>        at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
>        at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:79)
>        at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:87)
>        - locked <0x000000076ce96e58> (a
> io.netty.channel.nio.SelectedSelectionKeySet)
>        - locked <0x000000076ce96658> (a java.util.Collections$UnmodifiableSet)
>        - locked <0x000000076ce85be0> (a sun.nio.ch.EPollSelectorImpl)
>        at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:98)
>        at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:618)
>        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:306)
>        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
>        at java.lang.Thread.run(Thread.java:745)
> 
> the select doc :
> 
> /**
>     * Selects a set of keys whose corresponding channels are ready for I/O
>     * operations.
>     *
>     * <p> This method performs a blocking <a href="#selop">selection
>     * operation</a>.  It returns only after at least one channel is selected,
>     * this selector's {@link #wakeup wakeup} method is invoked, or the current
>     * thread is interrupted, whichever comes first.  </p>
>     *
>     * @return  The number of keys, possibly zero,
>     *          whose ready-operation sets were updated
>     *
>     * @throws  IOException
>     *          If an I/O error occurs
>     *
>     * @throws  ClosedSelectorException
>     *          If this selector is closed
>     */
>    public abstract int select() throws IOException;
> 
> so the select is blocck unitl a channel is selected, but the jstack
> java.lang.Thread.State: is RUNNABLE,why not is BLOCKED.
> 
> the offical api explain BLOCKED :
> 
> public static final Thread.State BLOCKEDThread state for a thread
> blocked waiting for a monitor lock. A thread in the blocked state is
> waiting for a monitor lock to enter a
> 
> synchronized block/method or reenter a synchronized block/method after
> calling Object.wait.
> 
> because that's Select block until  a channel is selected(not blocked
> waiting for a monitor lock) ,so it not the thread state BLOCKED.
> 
> am i right ?
> 
> -- 
>   =============================================
> 
>  fuyou001
> Best Regards



More information about the core-libs-dev mailing list