Java – In-use connections equal max-pool-size and expired max-wait-time. Cannot allocate more connections

database connectionjava

I am facing following problem with an HTTP 500 status.

Message description:

The server encountered an internal error () that prevented it from
fulfilling this request.

Exception:

javax.servlet.ServletException: java.sql.SQLException: Error in
allocating a connection. Cause: In-use connections equal max-pool-size
and expired max-wait-time. Cannot allocate more connections.

Root cause:

java.sql.SQLException: Error in allocating a connection. Cause: In-use
connections equal max-pool-size and expired max-wait-time. Cannot
allocate more connections.

note The full stack traces of the exception and its root causes are
available in the GlassFish v3 logs. GlassFish v3

Best Answer

Seems that you have a connection leak somewhere in your application.

When you borrow a connection from the connection pool and forget to properly close it, it remains marked as unavailable, causing the exception you are experiencing.

To locate the leak, you should monitor the connection usage through the JMX connector surely exposed by your application server.