因生产环境tomcat占用CPU持续过高,负载过高,重启tomcat过于缓慢,参与网上资料,解决tomcat占用CPU过高,重启缓慢问题

1、通过top命令找出占用CPU高的PID

top - 15:52:18 up 93 days,  2:23,  1 user,  load average: 9.05, 9.00, 9.17Tasks:  98 total,   1 running,  97 sleeping,   0 stopped,   0 zombieCpu(s): 41.0%us, 59.0%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%stMem:   3926224k total,  1070236k used,  2855988k free,    51508k buffersSwap:  6143992k total,   286684k used,  5857308k free,    95404k cached  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                               4834 root      20   0 1953m  62m 1848 S 99.2  1.6  28369:16 java                                                                 20399 root      20   0 1980m 650m 5724 S  0.3 17.0   6:31.53 java                                                                     1 root      20   0 19348  904  632 S  0.0  0.0   0:12.21 init                                                                     2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                                                                 3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                              4 root      20   0     0    0    0 S  0.0  0.0   2:50.30 ksoftirqd/0                                                              5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                              6 root      RT   0     0    0    0 S  0.0  0.0   0:11.41 watchdog/0                                                               7 root      20   0     0    0    0 S  0.0  0.0  47:36.80 events/0                                                                 8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cgroup                                                                   9 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper                                                                 10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 netns                                                                   11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr                                                               12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm                                                                      13 root      20   0     0    0    0 S  0.0  0.0   0:22.66 sync_supers                                                             14 root      20   0     0    0    0 S  0.0  0.0   0:21.60 bdi-default                                                             15 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kintegrityd/0                                                           16 root      20   0     0    0    0 S  0.0  0.0   1:41.28 kblockd/0                                                               17 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpid                                                                  18 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpi_notify                                                            19 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpi_hotplug

2、通过ps aux | grep pid 可以进一步确定是tomcat进程出了问题

3、显示线程列表

[root@tomcat-12 ~]# ps -mp 4834 -o THREAD,tid,timeUSER     %CPU PRI SCNT WCHAN  USER SYSTEM   TID     TIMEroot     85.4   -    - -         -      -     - 19-16:49:52root      0.0  19    - futex_    -      -  4834 00:00:00root      0.0  19    - futex_    -      -  4835 00:00:00root      0.0  19    - futex_    -      -  4836 00:00:47root      0.0  19    - futex_    -      -  4837 00:00:00root      0.0  19    - futex_    -      -  4838 00:00:01root      0.0  19    - futex_    -      -  4839 00:00:00root      0.0  19    - futex_    -      -  4840 00:00:20root      0.0  19    - futex_    -      -  4841 00:00:21root      0.0  19    - futex_    -      -  4842 00:00:00root      0.0  19    - futex_    -      -  4843 00:12:07root      0.0  19    - futex_    -      -  4844 00:00:00root      9.4  19    - -         -      -  4863 2-04:30:24root      9.4  19    - -         -      -  4871 2-04:30:20root      9.4  19    - -         -      -  4875 2-04:30:20root      9.4  19    - -         -      -  4890 2-04:30:20root      9.4  19    - -         -      -  4893 2-04:30:20root      9.4  19    - -         -      -  4896 2-04:30:20root      9.4  19    - -         -      -  4898 2-04:30:20root      9.4  19    - -         -      -  4904 2-04:30:20root      0.0  19    - futex_    -      -  4916 00:00:00root      0.0  19    - futex_    -      -  4917 00:00:10root      0.0  19    - futex_    -      -  4918 00:00:00root      0.0  19    - futex_    -      -  4919 00:00:00root      0.0  19    - futex_    -      -  4920 00:00:00root      0.0  19    - futex_    -      -  4921 00:00:00root      0.0  19    - futex_    -      -  4922 00:00:00root      0.0  19    - futex_    -      -  4923 00:00:00root      0.0  19    - futex_    -      -  4924 00:00:00root      0.0  19    - futex_    -      -  4925 00:00:00root      0.0  19    - futex_    -      -  4926 00:00:00root      0.0  19    - futex_    -      -  4927 00:00:00root      0.0  19    - futex_    -      -  4928 00:00:00root      0.0  19    - futex_    -      -  4929 00:00:00root      0.0  19    - futex_    -      -  4930 00:00:00root      0.0  19    - futex_    -      -  4931 00:00:00root      0.0  19    - futex_    -      -  4932 00:00:00root      0.0  19    - futex_    -      -  4933 00:00:00root      0.0  19    - futex_    -      -  4934 00:00:00root      0.0  19    - futex_    -      -  4935 00:00:00root      0.0  19    - futex_    -      -  4936 00:00:00root      0.0  19    - futex_    -      -  4937 00:00:00root      0.0  19    - futex_    -      -  4938 00:00:00root      0.0  19    - futex_    -      -  4939 00:00:00root      0.0  19    - futex_    -      -  4940 00:00:00root      0.0  19    - futex_    -      -  4941 00:00:00root      0.0  19    - futex_    -      -  4942 00:00:00root      0.0  19    - futex_    -      -  4943 00:00:00root      0.0  19    - futex_    -      -  4944 00:00:00root      0.0  19    - futex_    -      -  4945 00:00:00root      0.0  19    - futex_    -      -  4946 00:00:00root      0.0  19    - futex_    -      -  4947 00:00:00root      0.0  19    - futex_    -      -  4948 00:00:00root      0.0  19    - futex_    -      -  4949 00:00:00root      0.0  19    - futex_    -      -  4950 00:00:00root      0.0  19    - futex_    -      -  4951 00:00:00root      0.0  19    - futex_    -      -  4952 00:00:00root      0.0  19    - futex_    -      -  4953 00:00:00root      0.0  19    - futex_    -      -  4954 00:00:00root      0.0  19    - futex_    -      -  4955 00:00:00root      0.0  19    - futex_    -      -  4956 00:00:00root      0.0  19    - futex_    -      -  4957 00:00:00root      0.0  19    - futex_    -      -  4958 00:00:00root      0.0  19    - futex_    -      -  4959 00:00:00root      0.0  19    - futex_    -      -  4960 00:00:00root      0.0  19    - futex_    -      -  4961 00:00:00root      0.0  19    - futex_    -      -  4962 00:00:00root      0.0  19    - futex_    -      -  4963 00:00:00root      0.0  19    - futex_    -      -  4964 00:00:00root      0.0  19    - futex_    -      -  4965 00:00:00root      0.0  19    - futex_    -      -  4966 00:00:00root      0.0  19    - futex_    -      -  4967 00:00:00root      0.0  19    - futex_    -      -  4968 00:00:00root      0.0  19    - futex_    -      -  4969 00:00:00root      0.0  19    - futex_    -      -  4970 00:00:00root      0.0  19    - futex_    -      -  4971 00:00:00root      0.0  19    - futex_    -      -  4972 00:00:00root      0.0  19    - futex_    -      -  4973 00:00:00root      0.0  19    - futex_    -      -  4974 00:00:00root      0.0  19    - futex_    -      -  4975 00:00:00root      0.0  19    - futex_    -      -  4976 00:00:00root      0.0  19    - futex_    -      -  4977 00:00:00root      0.0  19    - futex_    -      -  4978 00:00:00root      0.0  19    - futex_    -      -  4979 00:00:00root      0.0  19    - futex_    -      -  4980 00:00:00root      0.0  19    - futex_    -      -  4981 00:00:00root      0.0  19    - futex_    -      -  4982 00:00:00root      0.0  19    - futex_    -      -  4983 00:00:00root      0.0  19    - futex_    -      -  4984 00:00:00root      0.0  19    - futex_    -      -  4985 00:00:00root      0.0  19    - futex_    -      -  4986 00:00:00root      0.0  19    - futex_    -      -  4987 00:00:00root      0.0  19    - futex_    -      -  4988 00:00:00root      0.0  19    - futex_    -      -  4989 00:00:00root      0.0  19    - futex_    -      -  4990 00:00:00root      0.0  19    - futex_    -      -  4991 00:00:00root      0.0  19    - futex_    -      -  4992 00:00:00root      0.0  19    - futex_    -      -  4993 00:00:00root      0.0  19    - futex_    -      -  4994 00:00:00root      0.0  19    - futex_    -      -  4995 00:00:00root      0.0  19    - futex_    -      -  4996 00:00:00root      0.0  19    - futex_    -      -  4997 00:00:00root      0.0  19    - futex_    -      -  4998 00:00:00root      0.0  19    - futex_    -      -  4999 00:00:00root      0.0  19    - futex_    -      -  5000 00:00:00root      0.0  19    - futex_    -      -  5001 00:00:00root      0.0  19    - futex_    -      -  5002 00:00:00root      0.0  19    - futex_    -      -  5003 00:00:00root      0.0  19    - futex_    -      -  5004 00:00:00root      0.0  19    - futex_    -      -  5005 00:00:00root      0.0  19    - futex_    -      -  5006 00:00:00root      0.0  19    - futex_    -      -  5007 00:00:00root      0.0  19    - futex_    -      -  5008 00:00:00root      0.0  19    - futex_    -      -  5009 00:00:00root      0.0  19    - futex_    -      -  5010 00:00:00root      0.0  19    - futex_    -      -  5011 00:00:00root      0.0  19    - futex_    -      -  5012 00:00:00root      0.0  19    - futex_    -      -  5013 00:00:00root      0.0  19    - futex_    -      -  5014 00:00:00root      0.0  19    - futex_    -      -  5015 00:00:00root      0.0  19    - futex_    -      -  5016 00:00:00root      0.0  19    - futex_    -      -  5017 00:00:00root      0.0  19    - futex_    -      -  5018 00:00:00root      0.0  19    - futex_    -      -  5019 00:00:00root      0.0  19    - futex_    -      -  5020 00:00:00root      0.0  19    - futex_    -      -  5021 00:00:00root      0.0  19    - futex_    -      -  5022 00:00:00root      0.0  19    - futex_    -      -  5023 00:00:00root      0.0  19    - futex_    -      -  5024 00:00:00root      0.0  19    - futex_    -      -  5025 00:00:00root      0.0  19    - futex_    -      -  5026 00:00:00root      0.0  19    - futex_    -      -  5027 00:00:00root      0.0  19    - futex_    -      -  5028 00:00:00root      0.0  19    - futex_    -      -  5029 00:00:00root      0.0  19    - futex_    -      -  5030 00:00:00root      0.0  19    - futex_    -      -  5031 00:00:00root      0.0  19    - futex_    -      -  5032 00:00:00root      0.0  19    - futex_    -      -  5033 00:00:00root      0.0  19    - futex_    -      -  5034 00:00:00root      0.0  19    - futex_    -      -  5035 00:00:00root      0.0  19    - futex_    -      -  5036 00:00:00root      0.0  19    - futex_    -      -  5037 00:00:00root      0.0  19    - futex_    -      -  5038 00:00:00root      0.0  19    - futex_    -      -  5039 00:00:00root      0.0  19    - futex_    -      -  5040 00:00:00root      0.0  19    - futex_    -      -  5041 00:00:00root      0.0  19    - futex_    -      -  5042 00:00:00root      0.0  19    - futex_    -      -  5043 00:00:00root      0.0  19    - futex_    -      -  5044 00:00:00root      0.0  19    - futex_    -      -  5047 00:00:00root      0.0  19    - futex_    -      -  5053 00:00:00root      0.0  19    - futex_    -      -  5264 00:00:00root      9.5  19    - -         -      -  7041 2-04:30:17root      0.0  19    - futex_    -      -  7366 00:00:00root      0.0  19    - futex_    -      -  7383 00:00:00root      0.0  19    - futex_    -      -  7385 00:00:00root      0.0  19    - futex_    -      -  7387 00:00:00root      0.0  19    - futex_    -      -  7388 00:00:00root      0.0  19    - futex_    -      -  7390 00:00:00root      0.0  19    - futex_    -      -  7397 00:00:35root      0.0  19    - skb_re    -      - 24683 00:00:00

通过观察共计7041、4904、4898、4896、4893、4890、4875、4871、4863九个tid占用了CPU

4、打印线程的堆栈信息

[root@tomcat-12 ~]jstack pid | grep tid -A 30

此处不一一列表各tid的堆栈信息了,在其中一个的tid堆栈信息中找到了问题的原因