Concurrent Access to HashMap Can Cause High CPU Usage
 Technote (FAQ)
 
Problem
Multiple threads accessing a HashMap/WeakHashMap concurrently can result in high CPU usage and application server performance degradation.
 
Cause
Applications that allow concurrent access to a HashMap or WeakHashMap object can experience high CPU utilization resulting in a Java™ Virtual Machine (JVM) hang or severe performance degradation.

To verify that you are experiencing this issue, collect the mustgather documentation for 100% CPU utilization for your given operating system (see the Related URL section) and determine the threads responsible for the CPU usage. In the case where concurrent HashMap access is causing the issue, the suspicious threads will be executing a Hashmap put/get, for example:

"Servlet.Engine.Transports : 7" (TID:1061B008, sys_thread_t:3160A90, state:R, native ID:26434) prio=5
at java.util.WeakHashMap.put
at org.apache.ojb.broker.singlevm.LoadedObjectsRegistry.register
at org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getDBObject
at org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getObjectByIdentity
at org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getObjectByQuery
at org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.getObjectByQuery
...

"Servlet.Engine.Transports : 4" (TID:104E9D88, sys_thread_t:2D0AEE8, state:R, native ID:1B031) prio=5
at java.util.WeakHashMap.put
at org.apache.ojb.broker.singlevm.LoadedObjectsRegistry.register
at org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getDBObject
at org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getObjectByIdentity
at org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getObjectByQuery
at org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.getObjectByQuery
...




The HashMap implementation is not synchronized; therefore, if multiple threads access the Hashmap concurrently it must be synchronized externally.

 
Solution
There are several methods to address this issue:
  1. Modify the application to use a HashTable instead of a HashMap.
  2. Create a HashMap with an adequate initial size to hold all the entries so that a rehash is not required to expand its size.
  3. Synchronize access to the HashMap in the application code.
 
Related information
1.4.2 SDK HashMap JavaDoc:
100% CPU Mustgather Technotes:
 
 
Cross Reference information
Segment Product Component Platform Version Edition
Application Servers Runtimes for Java Technology Java SDK
 
 


Document Information


Product categories: Software > Application Servers > Distributed Application & Web Servers > WebSphere Application Server > 100% CPU Usage
Operating system(s): Windows
Software version: 6.0
Software edition:
Reference #: 1240323
IBM Group: Software Group
Modified date: Jun 28, 2006