High CPU due to unsafe HashMap access in TomcatInjectionContainer.getEncInjectionsForClass
Environment
- JBoss Enterprise Application Server (EAP) 5
Issue
- JBoss is consuming high CPU and data shows the high CPU consumers are request threads making calls like the following:
"ajp-127.0.0.1-8009-1" daemon prio=10 tid=0x00002aabe3e24000 nid=0x2e40 runnable [0x000000005fdc9000..0x000000005fdd2c10]
java.lang.Thread.State: RUNNABLE
at java.util.HashMap.get(HashMap.java:303)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.getEncInjectionsForClass(TomcatInjectionContainer.java:443)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.getEncInjectionsForClass(TomcatInjectionContainer.java:446)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.getEncInjectionsForClass(TomcatInjectionContainer.java:446)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.getEncInjectionsForClass(TomcatInjectionContainer.java:446)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.getEncInjectionsForClass(TomcatInjectionContainer.java:446)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.getEncInjectionsForClass(TomcatInjectionContainer.java:446)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.getEncInjectionsForObject(TomcatInjectionContainer.java:435)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:355)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:271)
at org.apache.jasper.runtime.TagHandlerPool.get(TagHandlerPool.java:130)
Resolution
- Through these options, this injection will be disabled, which should eliminate the access of the encInjections hash map that's leading to high CPU:
-Dorg.apache.jasper.Constants.USE_INSTANCE_MANAGER_FOR_TAGS=false
-Dorg.apache.jasper.Constants.INJECT_TAGS=false
Root Cause
- It looks like these threads are getting stuck in high CPU loops because of concurrent access to a hash map, which is known to do that since it is not a thread safe collection. The hash map they are accessing is the encInjections hash map. This access is caused by injections from your tag libraries. This tag injection is typically not needed but it is enabled by default.
Diagnostic Steps
- Troubleshoot with CPU data and other diagnostic steps as described in Java application high CPU
Components
Category
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.