Today I have an app, which used near 100% CPU resource. I made some thread dumps. Found that:
"resin-port-8080-284" daemon prio=10 tid=0x00002ad370261000 nid=0x79c5 runnable [0x00002ad30b32d000]
java.lang.Thread.State: RUNNABLE
at java.util.HashMap.getEntry(HashMap.java:465)
at java.util.HashMap.get(HashMap.java:417)
at org.logicalcobwebs.proxool.proxy.InvokerFacade.getConcreteMethod(InvokerFacade.java:38)
at org.logicalcobwebs.proxool.WrappedConnection.invoke(WrappedConnection.java:111)
at org.logicalcobwebs.proxool.WrappedConnection.intercept(WrappedConnection.java:87)
at $java.lang.AutoCloseable$$EnhancerByProxool$$66bad385.getWarnings(<generated>)
at org.hibernate.util.JDBCExceptionReporter.logAndClearWarnings(JDBCExceptionReporter.java:45)
at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:472)
at org.hibernate.jdbc.ConnectionManager.cleanup(ConnectionManager.java:408)
at org.hibernate.jdbc.ConnectionManager.close(ConnectionManager.java:347)
at org.hibernate.impl.SessionImpl.close(SessionImpl.java:335)
The linked list in HashMap should have a cyclic chain, so the CPUs keep running and consumed all resources.
Proxool version is 0.9.0RC3 and Java is 1.7.
So I do not why it happen? Most of time the app is ok. And from the source code, the related Proxool classes seem to be thread-safe.
Is it Proxool's bug?
The InvokerFacade class has a static HashMap and mutates it without synchronization.
The HashMap documentation clearly states:
If multiple threads access a hash map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally
This is a defect and can lead to all sorts of strange behavior, including what you are observing here.
Explain the timing causing HashMap.put() to execute an infinite loop