Java專案伺服器cpu佔用100%解決辦法

科技小能手發表於2017-11-12

伺服器cpu佔用100% 

       專案上線後執行一段時間,突然發現cpu 8個邏輯核心都佔用100%,心情很緊張,然後就在網上找了一些解決方法,具體如下: 

       1.查詢哪些程式在耗cpu  

       進入伺服器,top 命令看一下,發現程式6633佔用了800% 

       [root@server ~]# top 

       2.把程式的棧dump到檔案裡,以便後面的分析

       [root@server ~]# jstack 23812 >> java.txt



       3.看看這個程式裡面哪些執行緒在佔用cpu 

       [root@server ~]# top -p 23812 -H 

       一大片佔用cpu很高的執行緒,選一個最高的吧,PID=15362

       4.接著要看剛才dump出來的java.txt日誌了,裡面會有23812這個程式下面每個執行緒的棧資訊,但是是十六進位制顯示的,所以先把5159轉換成16進位制 

       [root@server ~]# printf %0x 15362
       [root@server ~]# 3c02

       5.在cpu日誌裡找PID=3c02的執行緒 

       [root@server ~]# vi java.txt

         6.分析原因


[root@localhost ~]# grep “3c02” java.txt 

“JS executor for com.gargoylesoftware.htmlunit.WebClient@4e96f35e” #76858 daemon prio=5 os_prio=0 tid=0x00007f390000b800 nid=0x3c02 runnable [0x00007f3ae13db000]

“JS executor for com.gargoylesoftware.htmlunit.WebClient@4e96f35e” #76858 daemon prio=5 os_prio=0 tid=0x00007f390000b800 nid=0x3c02 runnable [0x00007f3ae13db000]

“JS executor for com.gargoylesoftware.htmlunit.WebClient@4e96f35e” #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開發排查

 本文轉自 wjw555 51CTO部落格,原文連結:http://blog.51cto.com/wujianwei/1964359


相關文章