IN_NATIVE在jstack文件中的含义是什么?

时间:2017-02-13 11:36:53

标签: java jstack

    Thread 10296: (state = IN_NATIVE)
 - sun.nio.ch.Net.connect0(boolean, java.io.FileDescriptor, java.net.InetAddress, int) @bci=0 (Interpreted frame)
 - sun.nio.ch.Net.connect(java.net.ProtocolFamily, java.io.FileDescriptor, java.net.InetAddress, int) @bci=25, line=465 (Interpreted frame)
 - sun.nio.ch.Net.connect(java.io.FileDescriptor, java.net.InetAddress, int) @bci=6, line=457 (Interpreted frame)
 - sun.nio.ch.SocketChannelImpl.connect(java.net.SocketAddress) @bci=225, line=670 (Interpreted frame)
 - kafka.network.BlockingChannel.connect() @bci=135 (Interpreted frame)
 - kafka.producer.SyncProducer.connect() @bci=21 (Interpreted frame)
 - kafka.producer.SyncProducer.getOrMakeConnection() @bci=11 (Interpreted frame)
 - kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(kafka.api.RequestOrResponse, boolean) @bci=13 (Interpreted frame)
 - kafka.producer.SyncProducer.send(kafka.api.TopicMetadataRequest) @bci=6 (Interpreted frame)
 - kafka.client.ClientUtils$.fetchTopicMetadata(scala.collection.Set, scala.collection.Seq, kafka.producer.ProducerConfig, int, kafka.auth.KafkaUser) @bci=189 (Interpreted frame)
 - kafka.producer.BrokerPartitionInfo.updateInfo(scala.collection.immutable.Set, int) @bci=24 (Interpreted frame)
 - kafka.producer.async.DefaultEventHandler$$anonfun$handle$2.apply$mcV$sp() @bci=54 (Interpreted frame)
 - kafka.utils.Utils$.swallow(scala.Function2, scala.Function0) @bci=1 (Interpreted frame)
 - kafka.utils.Logging$class.swallowError(kafka.utils.Logging, scala.Function0) @bci=12 (Interpreted frame)
 - kafka.utils.Utils$.swallowError(scala.Function0) @bci=2 (Interpreted frame)
 - kafka.producer.async.DefaultEventHandler.handle(scala.collection.Seq) @bci=269 (Interpreted frame)
 - kafka.producer.Producer.send(scala.collection.Seq) @bci=45 (Interpreted frame)
 - kafka.javaapi.producer.Producer.send(kafka.producer.KeyedMessage) @bci=21 (Interpreted frame)
 - com.tmri.cld.impl.kafka.SjKafkaClientUtil.sendMessage(java.lang.String, java.lang.String, byte[]) @bci=40, line=141 (Interpreted frame)
 - com.tmri.stream.handle.thread.w.SendLogDataThreadW.run() @bci=356, line=78 (Interpreted frame)
 - java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) @bci=95, line=1145 (Interpreted frame)
 - java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=5, line=615 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)

如上所示,我使用jstack来获取输出和调试,我用Google搜索并仍然没有得到明确的答案,任何人都可以告诉我IN_NATIVE状态在jstack输出文件中意味着什么?

1 个答案:

答案 0 :(得分:4)

在某些时候,大多数代码都必须与操作系统进行交互,并且“物理”代码必须与操作系统进行交互。硬件。 Java通过本机代码执行此操作,IN_NATIVE的JStack状态反映了这一点 - 它正在运行系统" native"代码而不是Java代码(例如,将数据写入文件)。有关本机代码的定义,请参阅this question的答案。

您看到的状态是VM依赖的,但很可能您正在运行Hotspot或类似的东西(OpenJDK,Oracle JDK等),因此following definitions应该成立:

  
      
  • UNINITIALIZED - 绝不应该发生(缺少初始化)
  •   
  • - 刚开始,即正在初始化
  •   
  • IN_NATIVE - 以原生代码运行
  •   
  • IN_NATIVE_TRANS - 对应的过渡状态
  •   
  • IN_VM - 在VM中运行
  •   
  • IN_VM_TRANS - 对应的过渡状态
  •   
  • IN_JAVA - 以Java或存根代码运行
  •   
  • 已阻止 - 已在vm中阻止
  •   
  • BLOCKED_TRANS - 对应的过渡状态
  •   

_TRANS后缀用于表示线程正在状态之间转换。请注意,未使用IN_JAVA_TRANS和NEW_TRANS状态,因此我将其从上面的列表中排除。