Database Connection does not release after idle time out in glassfish - mysql

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.

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.

Related

In mysql,For four connection strings , what will be minimum pool size?

what if we set minimum poll size to zero?
And, what will be a default minimum pool size ?
Here's the MySQL documentation on connection pooling, this is what it says:
Most applications only need a thread to have access to a connection
when they are actively processing a transaction, which often takes
only milliseconds to complete. When not processing a transaction, the
connection sits idle. Connection pooling enables the idle connection
to be used by some other thread to do useful work.
In your case, if you have 4 connection strings and they all are different (meaning they are connecting to different database server and/or database) then it's safe to say that your application will have at least 4 connections in pool.

MySQL connection timeout?

I have a spring-mvc application running on glassfish server with Mysql db connection in which the pool idle time is set to 300 seconds but I am getting continuously the Warnings every 5 minutes even if ther is no idle session even if the application is up in the server but no one is using it:
Unexpected exception while destroying resource from pool MediaTrackPool. Exception message: WEB9031: WebappClassLoader unable to load resource [com.mysql.jdbc.ProfilerEventHandlerFactory], because it has not yet been started, or was already stopped
Error while Resizing pool MediaTrackPool. Exception : WEB9031: WebappClassLoader unable to load resource [com.mysql.jdbc.SQLError], because it has not yet been started, or was already stopped
Could someone help me in getting rid of this warnings as or restricting them when actual ideal session is encountered because getting the warnings every 5 minutes even when no one using the application is not helping is real log analysis.
Settings for connection pool are as below:
General Settings
Pool Name: MediaTrackPool
Resource Type: javax.sql.DataSource
Datasource Classname:com.mysql.jdbc.jdbc2.optional.MysqlDataSource
Pool Settings
Initial and Minimum Pool Size: 8
Maximum Pool Size: 32
Pool Resize Quantity: 2
Idle Timeout: 300
Max Wait Time: 60000
I belive that there is a mismatch between the connection pool properties and the actual timeouts at the my sql server.
Can you check whats the value of connect_timeout, interactive_timeout and wait_timeout.
More info on setting these timouts is here.

DB connection pool expired, then what?

After my connection pool expires, when I try to open more connections in parallel than my max number of allowed connections in the pool, then I start getting timeout exceptions when trying to obtain a connection from the pool.
That is expected, however, the pool seems to be left in that state, where everything else I do since that moment gets the same timeout exceptions. As if each of the connections in the pool had been left busy, and can't be reused. I would expect the connections to get freed up over time, and then other connections being allowed, but this is not happening.
I'm using Play 1.2.5 with a jdbc driver to mysql, and from the logs I reckon the pool is C3P0.
I'm not explicitly closing the connections, since I believe is the right thing to do when using a pool, but I'm not 100% sure.
I don't know if this could be a connection leak in one of the framework/libraries I'm using, or if I'm doing something wrong or not doing something I should.
When I catch one of the timeout exceptions, what is the right thing to do?
You must explicitly close connections when you use a connection pool. A connection pool has a collection of physical connections to a database. When you request a connection from the pool, it marks that physical connection as in-use and hands you a logical handle to that connection. This logical handle essentially is a wrapper or proxy which forwards most method calls (either directly or with some modification) to the physical connection.
When you call close() on this logical handle, the connection pool gets a signal that the physical connection is available again (that is: can be returned to the pool), the logical handle will from then on behave as a closed connection, but the actual physical connection is still open. If you don't call close(), the connection pool never gets this signal so the physical connection will remain in-use and won't be available for re-use.
Some advanced pool configurations allows the pool to detect this situation (eg using a timeout, or maybe with finalizers etc) and reclaim the connection, but you should not depend on that.
TL;DR: Always call close() on your connection when you are done with it, whether it comes from a connection pool, a non-pooled DataSource or DriverManager.

Glassfish mysql connection usage

i have web app running on GF 3.1.1 using MYSQL connection pool. When i check connections to DB using : "show processlist;" i can see everytime that only one connection is used. Why is this happening? There are a lot of threads that do something with DB. Please can someone answer my question?
Thank you very much.
You're connection pool is a pool of available connections. You might have 32 connections available but that doesn't mean it will connect them all. It will manage the connections for you. As demand increases the number of open connections will increase till your max is reached. Likewise as demand decreases your open connections will decrease down to your minimum.
Assuming your queries are fast GF is probably deciding that 1 connection is all that's needed.
Having said all that, the default min connection is 8 so log into your Admin console and look at your connection pool settings. The number of open connections should be at least what the min is set too.

Does the setting time_out in mysql affect JDBC connection pool?

It's usually set to 60 seconds.
But I think con pool will hold the connection, so is there any conflict? Thank you.
Here is the answer from Glassfish Wiki:
idle-timeout-in-seconds
maximum time in seconds, that a connection can remain idle in
the pool. After this time, the pool implementation can close
this connection. ====>Note that this does not control connection
timeouts enforced at the database server side<====. Adminsitrators
are advised to keep this timeout shorter than the EIS
connection timeout (if such timeouts are configured on the
specific EIS), to prevent accumulation of unusable connection
in Application Server.