1. 程式人生 > >Java項目服務器cpu占用100%解決辦法

Java項目服務器cpu占用100%解決辦法

java項目服務器cpu占用100%解決辦法

服務器cpu占用100%

項目上線後運行一段時間,突然發現cpu 8個邏輯核心都占用100%,心情很緊張,然後就在網上找了一些解決方法,具體如下:
1.查找哪些進程在耗cpu
進入服務器,top 命令看一下,發現進程6633占用了800%
[[email protected] ~]# top
2.把進程的棧dump到文件裏,以便後面的分析
[[email protected] ~]# jstack 23812 >> java.txt


3.看看這個進程裏面哪些線程在占用cpu
[[email protected] ~]# top -p 23812 -H


一大片占用cpu很高的線程,選一個最高的吧,PID=15362
4.接著要看剛才dump出來的java.txt日誌了,裏面會有23812這個進程下面每個線程的棧信息,但是是十六進制顯示的,所以先把5159轉換成16進制
[[email protected] ~]# printf %0x 15362
[[email protected] ~]# 3c02
5.在cpu日誌裏找PID=3c02的線程

[[email protected] ~]# vi java.txt

6.分析原因


[[email protected] ~]# grep "3c02" java.txt

"JS executor for [email protected]" #76858 daemon prio=5 os_prio=0 tid=0x00007f390000b800 nid=0x3c02 runnable [0x00007f3ae13db000]

"JS executor for [email protected]" #76858 daemon prio=5 os_prio=0 tid=0x00007f390000b800 nid=0x3c02 runnable [0x00007f3ae13db000]

"JS executor for [email protected]" #76858 daemon prio=5 os_prio=0 tid=0x00007f390000b800 nid=0x3c02 runnab

java.lang.Thread.State: RUNNABLE

at java.util.ArrayList.<init>(ArrayList.java:177)

at com.gargoylesoftware.htmlunit.html.HtmlPage.safeGetAttributeListeners(HtmlPage.java:2222)

- locked <0x00000005cd622798> (a java.lang.String)

at com.gargoylesoftware.htmlunit.html.HtmlPage.fireHtmlAttributeReplaced(HtmlPage.java:2198)

at com.gargoylesoftware.htmlunit.html.HtmlElement.setAttributeNS(HtmlElement.java:213)

at com.gargoylesoftware.htmlunit.html.DomElement.setAttribute(DomElement.java:296)

at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration.writeToElement(CSSStyleDeclaration.java:652)

at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration.replaceStyleAttribute(CSSStyleDeclaration.java:576)

at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration.setStyleAttribute(CSSStyleDeclaration.java:550)

at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration.setZIndex(CSSStyleDeclaration.java:3956)

at sun.reflect.GeneratedMethodAccessor135.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:120)

at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject$GetterSlot.setValue(ScriptableObject.java:295)

at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject$RelinkedSlot.setValue(ScriptableObject.java:368)

at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.putImpl(ScriptableObject.java:2796)

at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.put(ScriptableObject.java:521)

at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration.put(CSSStyleDeclaration.java:2407)

at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.putProperty(ScriptableObject.java:2479)

at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1574)

at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1569)

at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1253)

at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)

at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)

at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411)

at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)

at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3057)

at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115)

at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:566)

at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:674)

- locked <0x00000005cd2f5a08> (a com.gargoylesoftware.htmlunit.html.HtmlPage)

at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)

at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)

at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:575)

at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:550)

at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:971)

at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptStringJob.runJavaScript(JavaScriptStringJob.java:50)

at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutionJob.run(JavaScriptExecutionJob.java:102)

at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl.runSingleJob(JavaScriptJobManagerImpl.java:328)

at com.gargoylesoftware.htmlunit.javascript.background.DefaultJavaScriptExecutor.run(DefaultJavaScriptExecutor.java:162)

at java.lang.Thread.run(Thread.java:745)

找到問題所在讓java開發排查

本文出自 “10931853” 博客,請務必保留此出處http://wujianwei.blog.51cto.com/10931853/1964359

Java項目服務器cpu占用100%解決辦法