简体   繁体   English

Java - 高CPU使用率

[英]Java - High cpu usage

I have a production web application running in Tomcat. 我有一个在Tomcat中运行的生产Web应用程序。 The web application uses struts 2 as MVC layer. Web应用程序使用struts 2作为MVC层。

We had an issue wherein one of the web servers spiked to 100% cpu usage. 我们遇到了一个问题,其中一个Web服务器飙升到100%的CPU使用率。 This issue lasted for over several hours. 这个问题持续了几个小时。 I took the thread dump and saw over several hundred threads in runnable state and the dumps show the same stack trace for most of the threads. 我接受了线程转储,并在可运行状态下查看了数百个线程,并且转储显示了大多数线程的相同堆栈跟踪。

TP-Processor2" daemon prio=10 tid=0x00002aab80880c00 nid=0x5b4f runnable [0x0000000043bff000..0x0000000043c05d90]
   java.lang.Thread.State: RUNNABLE
        at java.util.HashMap.get(HashMap.java:303)
        at com.opensymphony.xwork2.util.LocalizedTextUtil.buildMessageFormat(LocalizedTextUtil.java:620)
        at com.opensymphony.xwork2.util.LocalizedTextUtil.getDefaultMessage(LocalizedTextUtil.java:588)
        at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:461)
        at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:224)
        at com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:99)
        at org.apache.struts2.components.Text.end(Text.java:158)
        at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:43)
        at org.apache.jsp.parts.myjsp_jsp._jspx_meth_s_005ftext_005f2(myjsp_jsp.java:296)
        at org.apache.jsp.parts.myjsp_jsp._jspService(myjsp_jsp.java:94)

Now the code in question uses struts s:text tag and just fetches the value from a property file. 现在,有问题的代码使用struts s:text标签,只是从属性文件中获取值。 I am not sure why so many threads should get stuck over there (threads are in runnable state). 我不确定为什么这么多线程会被卡在那里(线程处于可运行状态)。

Can i get some help in resolving what could have gone wrong. 我可以帮助解决可能出错的问题。

A guess right out of left-field: you're not synchronizing multithreaded access properly. 从左侧字段开始猜测:您没有正确同步多线程访问。

java.util.HashMap is not threadsafe, and if accessed concurrently by multiple threads, one particular mode of failure is an infinite loop within a particular bucket . java.util.HashMap不是线程安全的,如果多个线程同时访问,一种特定的失败模式是特定存储桶中无限循环

Take a look at the map in question (indicated by the stacktrace), and see whether multiple threads are in fact able to access it without adequate synchronization. 看看有问题的地图(由堆栈跟踪指示),看看多个线程是否实际上能够在没有足够同步的情况下访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM