Without being able to access a java applications console is there a way to generate a stack trace for the application.

Solution Unverified - Updated -

Environment

  • Java 1.6 or higher (All platforms)

Issue

How to generate a stack trace frow a java application running as a windows service

When a java application is hung or unresponsive is there anyway of generating information ( a stack trace) on what the current state of the apploication is?

Resolution

If the application is running on JDK1.6 or higher there is a tool called jstack that can be used to generate a stack trace. Simply get the process id , PID, of the java application and pass it to jstack.

The PID of an application can be found up by opening the Windows Task Manager, looking under the Process tab and looking for the java.exe process.
Ensure jstack is available by adding the JDK's bin directory to the system PATH. That is:

set PATH=C:\Program Files\Java\jdk1.6.0_13\bin;%PATH%

Snip of example output from a FUSE Message Broker process:

C:\FUSE\fuse-message-broker-5.3.0.2>jstack 2192
2009-08-19 12:12:48
Full thread dump Java HotSpot(TM) Client VM (11.3-b02 mixed mode, sharing):
"DefaultMessageListenerContainer-76868" prio=6 tid=0x02ef4800 nid=0x17d4 in Obje
ct.wait() [0x03f9f000..0x03f9fd14]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        at org.apache.activemq.MessageDispatchChannel.dequeue(MessageDispatchChannel.java:77)
        - locked <0x095f72e0> (a java.lang.Object)
        at org.apache.activemq.ActiveMQMessageConsumer.dequeue(ActiveMQMessageConsumer.java:419)
        at org.apache.activemq.ActiveMQMessageConsumer.receive(ActiveMQMessageConsumer.java:542)
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveMessage AbstractPollingMessageListenerContainer.java:404)
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:307)
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:260)
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:944)

JDK1.6 has other monitoring tools which are of use when diagnosing problems with a java process see: Monitoring and Managing Java SE 6 Platform Applications

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.