Will connection pool keep oracle session staying active? - java

i have a question about connection pool and oracle database. if i set the min size of the connection pool to 5, does that means even when the app is idle, oracle database will still keep 5 sessions active? thanks!

Yes, it should keep connections even if app is idle. Good idea is to check if connection on pool is still alive. Wrappers like HikariCP/Commons DBCP handle such cases.
//edit
Connection pool wont start 5 connections on application start but it will initialize new connection if it will be needed. And of course pool can be set to shutdown connection after finishing operation on it.
Connection pool behavior doc link

Related

Project Reactor - ConnectionProvider.evictInBackground()

What is the benefit of using evictInBackground operation on ConnectionProvider which is used with HttpClient.create(connectionProvider) in springboot webflux ?
By default, the connection pool timeouts (maxIdleTime, maxLifeTime etc.) are checked on connection release or acquire operations and, if some timeout is reached, the connection is closed and removed from the connection pool. However, you can also configure the connection pool, by setting evictInBackground, to perform periodic checks on connections.
The configuration evictInBackground is often combined with disposeInactivePoolsInBackground to remove from the structures all inactive connection pools.

Will DB connection leakage cause too many inactive session in Oracle?

I was assigned a task about fixing too many inactive session in Oracle database which used in our Java application. We found there was java method which didn't close the JDBC connetion. I know this is a DB connection leakage, but I am not sure if it is the cause of the too many inactive session. I don't know if O can get to know which Java process cause this issue. Can someone help me?
I know this is a DB Connection leakage but I am not sure if it is the reason cause the too many too many inactive session.
Probably.
If each time you get a JDBC Connection you do actually create a new connection then you will also start a new session and when you do not close the connection then you will have an inactive session and the number of sessions will grow.
If you are using connection pooling then, when you close the connection, the connection is not actually closed but is returned to the pool. When the next connection is required it will request a connection from the pool and you will reuse the previous connection and the previous connection's session. In this case you should not see an increase in the total number of sessions while the connections are reused from the connection pool but you might see inactive sessions that are the pooled connections which are not currently in use.
It sounds like you are not using connection pooling and then the number of sessions will directly correlate to the number of connections.

How to free connections in Apache DBCP?

I am calling org.apache.commons.dbcp2.BasicDataSource#getConnection, then working with it, then calling Connection#close() when connection is not needed anymore.
Unfortunately, my pool grows infinitely and all connection are remain active.
How to put connection to idle, so pool could re-use it?

How are JDBC connections implemented?

I have a project in which I used HikariCP for JDBC connection pooling. And HikariCP works just great for my needs. It also logs the stats of the pool like below.
2014-12-03 10:16:08 DEBUG HikariPool:559 - Before cleanup pool stats loginPool (total=8, inUse=0, avail=8, waiting=0)
2014-12-03 10:16:08 DEBUG HikariPool:559 - After cleanup pool stats loginPool (total=7, inUse=1, avail=7, waiting=0)
Just for experimental purposes I closed all the MySQL connections for the configured database using MySQL Workbench. But, still I see HikariCP logging the stats like before though there are no actual connections to the database. When there was a request for connection it immediately established the connections(initial 8), so everything works great.
So, my question is how does these connections are managed or implemented? I think the reason why HikariCP logs stats, as if there were connections, is because it has valid in memory references to connections, which are actually non existent(with database).
Is my understanding correct?
When you close the connections using MySQL Workbench, you are closing them on the server end. On the JDBC (client) side, the previously established connections will remain in existence until the client code attempts to use them. At that point, they will be found to be "broken"; i.e. the client will get exceptions when it tries to use them.
The client-side JDBC Connection objects only get closed or recycled when they are returned to the connection pool by your Java application code.
The connection pool created 8 connections at startup. You say you disconnected them using the workbench. Most connection pools won't know the connection is disconnected until it gets used.
Your assumption is correct. You manually killed the connections but the pool has a handle to 8 sockets which it assumes are connected. Given time your connection pool may have checked the connections for validity and attempted to reconnect them. I can't speak for HikariCP but this is what modern connections pools do.

Tomcat JDBC Connection Pool - Connections stuck on active

My application uses Tomcat JDBC connection pool, with MySQL DB.
Seems like a process that run during the night (anti virus scan?) cause the memory and CPU on the machine to increase, and as a result connections from the pool stuck on active until the connection pool can't response to any connection request.
I'm getting errors like:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after statement closed.
Timeout: Pool empty. Unable to fetch a connection in 10 seconds, none available[size:100; busy:97; idle:0; lastwait:10000]. (That's weird, where are the remaining 3?)
Looking at a chart I'm generating describing the active connection state, it is flat until at some point it start increasing until it reach the maximum and stays there.
My connection pool is configure to remove unclosed connections (setRemoveAbandoned = true).
Do you have any idea how can I solve this issue?
I think this is because your application not closing connections after use. Please check your code and make sure all connections are closing after use.

Categories