Database Connection does not release after idle ti

2019-06-11 06:43发布

问题:

i am using Glassfish 3 & mysql5.6.11.

i have created JDBC connection pool in glassfish.

Initial and Minimum Pool Size: - 8
Maximum Pool Size: -30
Pool Resize Quantity:- 10
Idle Timeout: - 60 (second).
Max Wait Time:- 2500 (millisecond).

with this parameter i have created pool setting.

i have set pool resize quantity value.

when no of connections increase, it does not release after idle time-out. next time when i hit url it again increase no of connection, it does not reuse already open connection.

i am getting 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.

i am using show processlist in mysql to show open connection.

if any one knows the solution of this problem, please share your idea with me.

i need help from any one.

回答1:

Idle timeout is just the time that unused connections in the pool will remain in the pool before they are closed/recycled. That problem you are having is most likely that you are not closing your connections after use.

Fix your code to close connections when you are done with them, closing a connection will release it back to the connection pool so they are available for reuse.

Some connection pools have additional timeouts for the time a connection can be used, forcing the connection back in the pool after that time. Which to the user of that connection will look as if the connection has been closed. I don't think the glassfish pool has this option though.