jstack命令(Java Stack Trace)

jstack用于打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息,如果是在64位机器上,需要指定选项"-J-d64",Windows的jstack使用方式只支持以下的这种方式。

例如说,通过:

ps ax | grep java

找到java的进程ID

jstack  

堆栈信息:

-- ::
Full thread dump Java HotSpot(TM) -Bit Server VM (24.71-b01 mixed mode):

 tid=0x00007fbce48bb000 nid=0x330b waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce528e800 nid=0x5903 waiting on condition [0x0000000118d05000]
   java.lang.Thread.State: TIMED_WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000007d7610080> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.)
    at kafka.consumer.ZookeeperConsumerConnector$ZKRebalancerListener$$anon$.run(ZookeeperConsumerConnector.scala:)

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce52ea000 nid=0x5703 waiting on condition [0x0000000118c02000]
   java.lang.Thread.State: TIMED_WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000007d7600440> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:)
    at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:)
    at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:)
    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:)
    at java.lang.Thread.run(Thread.java:)

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce52e4800 nid=0x5503 waiting on condition [0x0000000118aff000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000007d7608408> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.)
    at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:)
    at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:)

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce536e000 nid=0x5303 runnable [0x00000001189fc000]
   java.lang.Thread.State: RUNNABLE
    at sun.nio.ch.KQueueArrayWrapper.kevent0(Native Method)
    at sun.nio.ch.KQueueArrayWrapper.poll(KQueueArrayWrapper.java:)
    at sun.nio.ch.KQueueSelectorImpl.doSelect(KQueueSelectorImpl.java:)
    at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:)
    - locked <)
    - locked <0x00000007d76101e0> (a java.util.Collections$UnmodifiableSet)
    - locked <0x00000007d7610180> (a sun.nio.ch.KQueueSelectorImpl)
    at sun.nio.ch.SelectorImpl.)
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:)

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce52e3800 nid=0x5207 waiting on condition [0x00000001188f9000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000007d7608500> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.)
    at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:)
    at org.I0Itec.zkclient.ZkEventThread.run(ZkEventThread.java:)

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce5373000 nid=0x4b03 waiting on condition [0x00000001187f1000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000007d76085f0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.)
    at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:)
    at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:)
    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:)
    at java.lang.Thread.run(Thread.java:)

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce539a000 nid=0x4903 waiting on condition [0x00000001186ee000]
   java.lang.Thread.State: TIMED_WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000007d76085f0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:)
    at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:)
    at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:)
    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:)
    at java.lang.Thread.run(Thread.java:)

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce4022800 nid=0x4503 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce4021800 nid=0x4303 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce503b000 nid=0x4103 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce5035000 nid=0x3413 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce5032800 nid=0x2d03 in Object.wait() [0x0000000116146000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x00000007d7618ca0> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.)
    - locked <0x00000007d7618ca0> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.)
    at java.lang.)

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce5031800 nid=0x2b03 in Object.wait() [0x0000000116043000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x00000007d76189c8> (a java.lang.ref.Reference$Lock)
    at java.lang.Object.wait(Object.java:)
    at java.lang.)
    - locked <0x00000007d76189c8> (a java.lang.ref.Reference$Lock)

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce5801000 nid=0x1303 waiting on condition [0x000000010c900000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000007d760c9e8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.)
    at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:)
    at kafka.consumer.ConsumerIterator.makeNext(ConsumerIterator.scala:)
    at kafka.consumer.ConsumerIterator.makeNext(ConsumerIterator.scala:)
    at kafka.utils.IteratorTemplate.maybeComputeNext(IteratorTemplate.scala:)
    at kafka.utils.IteratorTemplate.hasNext(IteratorTemplate.scala:)
    at KafkaConsumer.consume(KafkaConsumer.java:)
    at KafkaConsumer.main(KafkaConsumer.java:)

   Locked ownable synchronizers:
    - None

 tid=0x00007fbce502f000 nid=0x2903 runnable 

 tid=0x00007fbce5001800 nid=0x2103 runnable 

 tid=0x00007fbce5002000 nid=0x2303 runnable 

 tid=0x00007fbce5002800 nid=0x2503 runnable 

 tid=0x00007fbce4806000 nid=0x2703 runnable 

 tid=0x00007fbce401e800 nid=0x4703 waiting on condition 

JNI 

相关说明:

1.命令格式

jstack [ option ] pid
jstack [ option ] executable core
jstack [ option ] [server-id@]remote-hostname-or-IP

2、常用参数说明

1)options:

executable Java executable from which the core dump was produced.

(可能是产生core dump的java可执行程序)

core 将被打印信息的core dump文件

remote-hostname-or-IP 远程debug服务的主机名或ip

server-id 唯一id,假如一台主机上多个远程debug服务

2)基本参数:

-F当’jstack [-l] pid’没有相应的时候强制打印栈信息

-l长列表. 打印关于锁的附加信息,例如属于java.util.concurrent的ownable synchronizers列表.

-m打印java和native c/c++框架的所有栈信息.

-h | -help打印帮助信息

pid 需要被打印配置信息的java进程id,可以用jps查询.

有篇分析的文章写得特别的好,忍不住分享了:

http://jameswxx.iteye.com/blog/1041173

上一篇:搭建Pypi转发服务


下一篇:hadoop群集安装中碰到的问题