Identifying the pid of Java process
Use the commandline JDK tool jps.
Getting Thread Dump of the particular Java process
Use the commandline JDK tool jstack:
$ jstack <pid> > 1.txt
$ jstack <pid> > 2.txt
$ jstack <pid> > 3.txt
Give some time gap between each execution of jstack. Analyze each log to find repeatable pattern. The thread which is common across each of these dumps is possibly causing the 100% CPU usage.
Use top to analyze Java process's thread CPU usage
$ top -Hp <pid>
The -H option will show CPU & Memory usage of the process per thread.
Windows Users: Process Monitor seems to display similar data in Windows:
http://technet.microsoft.com/hi-in/sysinternals/bb896645(en-us).aspx
Process Monitor is compatible with 64-bit Windows too.
Sample Program to simulate 100% CPU usage
Source: http://forums.sun.com/thread.jspa?threadID=5440980
class Empty implements Runnable {
Empty() {}
public void run() {
while(true) {}
}
public static void main(String[] arg) {
new Thread(new Empty()).start();
new Thread(new Empty()).start();
new Thread(new Empty()).start();
new Thread(new Empty()).start();
}
}
|