0

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?

Andremoniy
  • 34,031
  • 20
  • 135
  • 241
Yang Lifan
  • 445
  • 6
  • 15

1 Answers1

0

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

Infinite loop in java.util.HashMap

Community
  • 1
  • 1
Brett Okken
  • 6,210
  • 1
  • 19
  • 25
  • Yes, just look at `InvokerFacade` code, it is not thread safe. But I am not sure whether classes which use `InvokerFacade` have fully protections for the concurrent access. – Yang Lifan Feb 17 '17 at 06:58
  • The evidence indicates they do not. Indeed, by using a static variable, it makes it impractical to externally synchronize. – Brett Okken Feb 20 '17 at 13:28