As per my understanding, making a select/epoll/kqueue system call blocks a thread or process making the call, till a socket is ready for IO or the timeout event occurs. When doing a Thread Dump analysis on a netty based program I am seeing the parent group thread is in runnable state after making select call,
"Parent Group1" #11 prio=5 os_prio=0 tid=0x000000001e575000 nid=0x3f98 runnable [0x000000001f2ce000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x000000076bb59088> (a io.netty.channel.nio.SelectedSelectionKeySet)
- locked <0x000000076b9706b8> (a java.util.Collections$UnmodifiableSet)
- locked <0x000000076b970308> (a sun.nio.ch.WindowsSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:101)
at io.netty.channel.nio.SelectedSelectionKeySetSelector.select(SelectedSelectionKeySetSelector.java:68)
at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:803)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:457)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at java.lang.Thread.run(Thread.java:745)
Do Java threads appear Runnable even if it is waiting on system call or am I missing something.
As you can see from the dump, yes they are.
Java threads are not "runnable" only if blocked using a Java built-in synchronization mechanism, like waiting to enter a monitor (eg Object.wait
, Thread.sleep
, Thread.join
).
Native calls to select
/ epoll
/ kqueue
and JNI do not affect thread state.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.