当我的java应用程序变得无响应时,我使用jstack -F
(如果我在没有-F
标志的情况下运行jstack
,它不会给我任何东西)命令来转储线程信息,并且转储文件中有一个特殊的线程。
Thread 110175: (state = IN_VM) - sun.misc.Unsafe.freeMemory(long) @bci=0 (Compiled frame; information may be imprecise) - java.nio.DirectByteBuffer$Deallocator.run() @bci=17, line=94 (Compiled frame) - sun.misc.Cleaner.clean() @bci=12, line=143 (Compiled frame) - io.netty.util.internal.Cleaner0.freeDirectBuffer(java.nio.ByteBuffer) @bci=34, line=66 (Compiled frame) - io.netty.util.internal.PlatformDependent0.freeDirectBuffer(java.nio.ByteBuffer) @bci=1, line=147 (Compiled frame) - io.netty.util.internal.PlatformDependent.freeDirectBuffer(java.nio.ByteBuffer) @bci=13, line=281 (Compiled frame) - io.netty.buffer.UnpooledUnsafeDirectByteBuf.freeDirect(java.nio.ByteBuffer) @bci=1, line=115 (Compiled frame) - io.netty.buffer.UnpooledUnsafeDirectByteBuf.deallocate() @bci=24, line=508 (Compiled frame) - io.netty.buffer.AbstractReferenceCountedByteBuf.release() @bci=39, line=106 (Compiled frame) - io.netty.util.ReferenceCountUtil.release(java.lang.Object) @bci=11, line=59 (Compiled frame) - io.netty.util.ReferenceCountUtil.safeRelease(java.lang.Object) @bci=1, line=84 (Compiled frame) - io.netty.channel.ChannelOutboundBuffer.remove() @bci=40, line=258 (Compiled frame) - io.netty.channel.ChannelOutboundBuffer.removeBytes(long) @bci=83, line=334 (Compiled frame) - io.netty.channel.socket.nio.NioSocketChannel.doWrite(io.netty.channel.ChannelOutboundBuffer) @bci=238, line=301 (Compiled frame) - io.netty.channel.AbstractChannel$AbstractUnsafe.flush0() @bci=89, line=716 (Compiled frame) - io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.flush0() @bci=9, line=303 (Compiled frame) - io.netty.channel.AbstractChannel$AbstractUnsafe.flush() @bci=15, line=685 (Compiled frame) - io.netty.channel.DefaultChannelPipeline$HeadContext.flush(io.netty.channel.ChannelHandlerContext) @bci=4, line=1118 (Compiled frame) - io.netty.channel.AbstractChannelHandlerContext.invokeFlush() @bci=8, line=663 (Compiled frame) - io.netty.channel.AbstractChannelHandlerContext.access$1500(io.netty.channel.AbstractChannelHandlerContext) @bci=1, line=32 (Compiled frame) - io.netty.channel.AbstractChannelHandlerContext$16.run() @bci=4, line=651 (Compiled frame) - io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(long) @bci=26, line=380 (Compiled frame) - io.netty.channel.nio.NioEventLoop.run() @bci=106, line=357 (Compiled frame) - io.netty.util.concurrent.SingleThreadEventExecutor$2.run() @bci=13, line=116 (Interpreted frame) - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)
在我使用jstack -F
之后,应用程序开始响应并继续下去,就像什么也没发生一样,直到它最终再次停止响应。
当应用正常时,我使用jstack -F
搜索最后一个线程,它总是IN_NATIVE
。
这是我的问题。
- 此线程会使我的应用程序无响应吗?
- 这个话题是什么?
最佳答案
正如您在线程的堆栈跟踪中看到的,大多数调用都在 io.netty
包中。
底部的两个类,SingleThreadEventExecutor 和 NioEventLoop,在它们的 Javadoc 中表明它们是通用事件调度程序线程。因此,其中运行的代码可以是任何代码。据推测,它经常运行您的代码。
所以回答你的问题
- 是的,但前提是它运行的代码需要太长时间/使用太多 CPU 来处理您的硬件配置的事件。这可能是来自 netty 框架的其他代码,也可能是您的代码。
- 这是一个通用事件调度程序线程。这不是一个特殊的线程。
关于java - 转储文件中的特殊 java 线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34407515/