Java – Glassfish Server4 maximum pool size and max wait time

glassfishjava

The Glassfish4 server installed on my machine has Maximum Pool Size = 32 connections. Two cron jobs are scheduled from my application after every 10 and 15 mins on this server. The server crashed after 2 hours with the exception "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."

So, I altered the JDBC Connection pool settings and put in really large numbers just to see what would happen.

Maximum Pool Size: 1000000000 (1 billion)
Max Wait Time: 300000 (5 minutes)

Now my cron jobs are running fine.

Do you think having set the JDBC Connection pool attributes this high could cause issues? Please advise what values will be optimum.

Best Answer

I have resolved this issue with below settings in Glassfish4

Initial and Minimum Pool Size:16

Maximum Pool Size:64

Pool Resize Quantity:4

Idle Timeout:60

Max Wait Time:3000

I enabled connection leak monitoring in Glassfish4.

After enabling connection leak monitoring, when I checked the monitored data after some time, I could see ConnectionLeak exception in logs in some of my java classes. I closed the connections in these classes as they were being made directly from Connection object and JPA Entity Manager was not used in them.

Now all my cron jobs are running without Server crash.