http://blog.csdn.net/chenhaotong/article/details/51991786
1. Top command to view CPU and memory usage
Top carriage, then press 1
Discovery process PID 35163 CPU and memory usage is high
top-06:13:47 up 5:31, 1 user, load average:2.11, 2.07, 2.06
tasks:189 Total, 1 running, 188 sleeping, 0 stopped, 0 zombie
Cpu0:22.3%us, 0.7%sy, 0.0%ni, 76.4%id, 0.3%wa, 0.3%hi, 0.0%si, 0.0%st
Cpu1:100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu2:8.0%us, 0.3%sy, 0.0%ni, 91.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu3:70.4%us, 1.7%sy, 0.0%ni, 25.6%id, 2.3%wa, 0.0%hi, 0.0%si, 0.0%st
mem:1012292k Total, 943076k used, 69216k free, 9372k buffers
swap:1675260k Total, 375204k used, 1300056k free, 34024k cached
PID USER PR NI virt RES SHR S%cpu%mem time+ COMMAND
35163 user111 0 3823m 360m 6828 S 199.5 36.5 147:41.46 java
Also, under top, press H to toggle between process pid and thread Tid
2. View the PID corresponding process
[user111@kms210 lms]$ Ps-ef|grep 35163
user111 35163 1 04:59 pts/0 02:28:06/usr/local/jdk1.8.0_60/bin/java-djava.util.logging.config.file=/usr/local /lms/conf/logging.properties-djava.util.logging.manager=org.apache.juli.classloaderlogmanager- Djava.awt.headless=true-djava.endorsed.dirs=/usr/local/lms/endorsed-classpath/usr/local/lms/bin/bootstrap.jar :/usr/local/lms/bin/tomcat-juli.jar-dcatalina.base=/usr/local/lms-dcatalina.home=/usr/local/lms- Djava.io.tmpdir=/usr/local/lms/temp org.apache.catalina.startup.Bootstrap Start
user111 44605 23049 0 06:14 pts/0 00:00:00 grep 35163
3. View CPU-intensive processes in thread 35163
[user111@kms210 lms]$ ps-mp 35163-o thread,tid,time
User%cpu PRI SCNT wchan user SYSTEM TID time
user111 199-----02:32:04
user111 0.0 19-futex_--35163 00:00:00
user111 0.0 19-poll_s--35164 00:00:01
user111 0.0 19-futex_--35165 00:00:01
user111 0.0 19-futex_--35166 00:00:00
user111 0.0 19-futex_--35167 00:00:00
user111 0.0 19-futex_--35168 00:00:00
user111 0.3 19-futex_--35169 00:00:16
user111 0.3 19-futex_--35170 00:00:16
user111 0.1 19-futex_--35171 00:00:05
user111 0.0 19-futex_--35172 00:00:00
user111 0.0 19-futex_--35173 00:00:01
user111 0.0 19-futex_--35174 00:00:00
user111 0.0 19-futex_--35178 00:00:00
user111 0.0 19-ep_pol--35181 00:00:00
user111 0.0 19-ep_pol--35182 00:00:00
user111 0.0 19-ep_pol--35183 00:00:00
user111 99.6 19----35204 01:15:33
user111 0.0 19-futex_--35222 00:00:00
user111 99.6 19----35226 01:15:27
user111 0.0 19-futex_--35230 00:00:00
Thread Tid 16
[user111@kms210 lms]$ printf "%x\n" 35204
8984
4. View Thread stack information
[user111@kms210 lms]$ jstack 35163 | grep 8984-a 30
"Thread-6" #18 daemon prio=5 os_prio=0 tid=0x00007fb0d8fd1800 nid=0x8984 runnable [0x00007fb11cc8e000]
Java.lang.Thread.State:RUNNABLE
At Com.qsd.sssm.thread.LmsThread.run (lmsthread.java:68)
"Nioblockingselector.blockpoller-3" #15 daemon prio=5 os_prio=0 tid=0x00007fb130531800 nid=0x896f runnable [ 0X00007FB11DFB2000]
Java.lang.Thread.State:RUNNABLE
At Sun.nio.ch.EPollArrayWrapper.epollWait (Native method)
At Sun.nio.ch.EPollArrayWrapper.poll (epollarraywrapper.java:269)
At Sun.nio.ch.EPollSelectorImpl.doSelect (epollselectorimpl.java:79)
At Sun.nio.ch.SelectorImpl.lockAndDoSelect (selectorimpl.java:86)
-Locked <0x00000000f62278e8> (a sun.nio.ch.util$2)
-Locked <0x00000000f62278f8> (a java.util.collections$unmodifiableset)
-Locked <0x00000000f62278a0> (a Sun.nio.ch.EPollSelectorImpl)
At Sun.nio.ch.SelectorImpl.select (selectorimpl.java:97)
At Org.apache.tomcat.util.net.nioblockingselector$blockpoller.run (nioblockingselector.java:342)
"Nioblockingselector.blockpoller-2" #14 daemon prio=5 os_prio=0 tid=0x00007fb130517000 nid=0x896e runnable [ 0X00007FB11E0B3000]
Java.lang.Thread.State:RUNNABLE
At Sun.nio.ch.EPollArrayWrapper.epollWait (Native method)
At Sun.nio.ch.EPollArrayWrapper.poll (epollarraywrapper.java:269)
At Sun.nio.ch.EPollSelectorImpl.doSelect (epollselectorimpl.java:79)
At Sun.nio.ch.SelectorImpl.lockAndDoSelect (selectorimpl.java:86)
-Locked <0x00000000f6227b20> (a sun.nio.ch.util$2)
-Locked <0x00000000f6227b30> (a java.util.collections$unmodifiableset)
-Locked <0x00000000f6227ad8> (a Sun.nio.ch.EPollSelectorImpl)
At Sun.nio.ch.SelectorImpl.select (selectorimpl.java:97)
At Org.apache.tomcat.util.net.nioblockingselector$blockpoller.run (nioblockingselector.java:342)
"Nioblockingselector.blockpoller-1" #13 daemon prio=5 os_prio=0 tid=0x00007fb130474800 nid=0x896d runnable [ 0X00007FB11E3CD000]
Java.lang.Thread.State:RUNNABLE
At Sun.nio.ch.EPollArrayWrapper.epollWait (Native method)
[User111@kms210 lms]$
Locate the code that has the problem, and analyze the code snippet in the specific function that might appear to be dead loops.
Usually the problem occurs in a while, a loop code fragment for such a.
5. View File lmsthread.java:68 Line
Debug, find the Dead loop
while (true) {
if (CMD.remoteIp.equals ("")) {//Line 58th, if set, dead loop
Continue
}
6. In addition, only the possible problems of replacing the. War file
Modify to replace only the. war file, you may find that the thread occupancy rate is still very high, the thread stack information still displays the previous line number, you can try the complete Delete project folder, redeploy the entire project
But we can turn around and try this:
1 First with PS + grep to find the damn process PID, such as 30420
2 Top-h-P 30420, all threads for the process are listed. See which thread PID takes up the most, and then converts this PID to 16, such as 44BF, and note that you want to lowercase
3 Jstack 30420 | Less, and then look for NID=0X44BF, oh, found (if you can't find the corresponding Nid, you can remove | Less the following Jstack command) P.S serious hint: jstack operation is risky, use virtual caution, I have more than one execution Jstack operation led to the JVM exit, I do not know why, RP Ah rp ... It would have been safer to use JMX, but the Threadinfo Doc didn't find a way around it.