Search code examples
jakarta-eejpajava-ee-6glassfish-3

How to find a ininite loop in glassfishv3


I have s.t. like a infinite loop some where in the code. That place is somehow not called often. So after a couple of hours one of the CPU's on the Linux machine start's running at 100% then after a while another one etc. Restarting the server solves the problem for a while.

How can i find the place where this happens?

I thought about setting the RequestTimeout very small. (5 min) Would I get a proper error message in the log that tells me what's wrong.

top with command "H"

16639 java 20 0 9836m 2.6g 17m R 100 16.5 39:55.33 java 18059 java 20 0 2745m 2.3g 17m S 2 14.5 0:00.92 java 16591 java 20 0 9836m 2.6g 17m S 1 16.5 0:15.97 java 5307 java 20 0 8945m 4.6g 3864 S 1 29.1 746:47.67 java

and then: jstack -J-d64 16639

But I get: 16639: Unable to open socket file: target process not responding or HotSpot VM not loaded The -F option can be used when the target process is not responding

Must I start s.t. on the machine before?

Nice article about how to search for the hotspot:

http://code.nomad-labs.com/2010/11/18/identifying-which-java-thread-is-consuming-most-cpu/


Solution

  • If you have privileges in the machine you can execute jstack.

    jstack execute a thread dump on the application. From there you can check which thread is in an infinite loop.

    Jstack is bundled with the jdk.

    Another way is to check top command (*nix) and enable the thread view. From there you can check which thread is consuming the cpu. Then with jstack you can see a nid which is the hexadecimal value of the thread.

    You can use jps to obtain java pid.