How do I find infinite loops in Java Web applications?
One day, the CPU utilization of our Java Web application reached 100%
We try to find the problem by using kill - quit to dump multiple threads and view and compare the details of each thread We found a thread call stack in all thread dumps After analysis, there is a while loop condition. For some data updated regularly in the database, it will never make an error
Analyzing several thread dumps of web applications is cumbersome
So do you know a better way or tool to find such problems in a production environment?
Solution
After some inquiries, I found the answer in monitoring and managing Java se 6 platform applications:
You can use the tool named jtop provided by JDK to diagnose circular threads, which will display the CPU time used by each thread:
Using the thread name, you can find the stack trace of this thread in the "threads" tab by using kill - quit for thread dump
You can now focus on the code that causes an infinite loop
PS.: according to http://blog.stackoverflow.com/2008/07/stack-overflow-private-beta-begins/ It seems no problem to answer my own question: [...] "yes, if you can find a good answer in front of others, you can answer your own question." […]
PS.: if sun COM domain name will no longer exist: you can run jtop as a stand-alone GUI:
$<JDK>/bin/java -jar <JDK>/demo/management/JTop/JTop.jar
Alternatively, you can run it as a jconsole plug-in:
$<JDK>/bin/jconsole -pluginpath <JDK>/demo/management/JTop/JTop.jar