Command Line Analysis of java thread CPU usage, command line java thread cpu
1. Use the top command to find the JAVA Process pid with the highest cpu usage
2. Find the thread with the highest cpu usage:
Top-Hppid-d 1-n 1
3. Print the stack information of the JAVA Process pid that occupies the highest CPU
Jstack pid>/tmp/stacktrace. log
4. Convert the highest CPU thread number into a hex number to stacktrace. log to find the corresponding thread hexadecimal value and find the thread code.
Java obtains the cpu usage of a thread.
Blog.csdn.net/..9.aspx
Here you need
How can I determine whether a thread is occupying CPU resources in java?
The Java platform was designed as a multi-threaded environment from the very beginning. When your main program is executed, other jobs, such as fragment collection and event processing, are performed in the background. Essentially, you can think of these jobs as threads. They are System Management threads, but in any case they are threads. Threads enable you to define independent jobs and do not interfere with each other. The system will switch these jobs into or out of the CPU, so that (from the external perspective) They seem to run at the same time.
When you need to process multiple jobs in your program, you can also use multiple processes. These processes can be created by yourself, and you can manipulate system threads.
You need to use several different classes or interfaces to process these multiple jobs:
Java. util. Timer class
Javax. swing. Timer class
Thread class
Runnable interface
For simple jobs, they usually need to be repeated. You can use the java. util. Timer class to tell it to "do it once every half a second ". Note: Most system routines use milliseconds. Half a second is 500 milliseconds.
The task that you want Timer to implement is defined in the java. util. TimerTask instance. The running method includes the task to be executed. These are demonstrated in the Hi class, where the string "Hi" is repeatedly displayed on the screen until you press Enter.
Import java. util .*;
Public class Hi {
Public static void main (String args [])
Throws java. io. IOException {
TimerTask task = new TimerTask (){
Public void run (){
System. out. println ("Hi ");
}
};
Timer timer = new Timer ();
Timer. schedule (tasks, 0,500 );
System. out. println ("Press ENTER to stop ");
System. in. read (new byte [10]);
Timer. cancel ();
}
}
Java Runtime Environment works by running the program as long as one thread is running. In this way, when the cancellation is called and no other threads are running, the program exits. Some system threads are running, such as the fragment collection program. These System threads are also called background threads. The background thread does not affect the running environment. Only non-Background threads ensure that the running environment is not disabled.
Related materials: www.yesky.com/123/1738123.shtml