Heruan Heruan - 3 months ago 102
Java Question

How to fine-tune a JPA/JAX-RS application

I've developed a JAX-RS JSON API in Wildfly/RESTeasy with a JPA/Hibernate backend and I have serious database access problems.

For example, suddenly the application stop responding and the logs show a bunch of:

ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (EJB default - 4) IJ031012: Unable to obtain lock in 60 seconds: org.jboss.jca.adapters.jdbc.local.LocalManagedConnection

INFO [org.jboss.jca.core.connectionmanager.listener.TxConnectionListener] IJ000302: Unregistered handle that was not registered: org.jboss.jca.adapters.jdbc.jdk7.WrappedConnectionJDK7

WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] IJ000609: Attempt to return connection twice: org.jboss.jca.core.connectionmanager.listener.TxConnectionListener

WARN [org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory] (default task-9) IJ030020: Detected queued threads during cleanup

ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ForkJoinPool.commonPool-worker-0) IJ031041: Connection handle has been closed and is unusable

ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ForkJoinPool.commonPool-worker-1) IJ031050: The result set is closed

I think this is due to multiple access by different users (say 15, 20 users simultaneously), since with one/two users this not happens.

I'm on Hibernate 5.1 and Wildfly 10, and SQL Server 2014. It is a vanilla installation, with no tweaks or custom configurations. How can I fine-tune the infrastructure to avoid these issues?


The problem was related to the REST services being @Stateless and therefore opening transactions on each request. The solution was to inject @Stateless DAOs into the REST services: no more locking issues.