How can i stop database retry connection?using c3po i.e in my application i want to stop retry connection when i get database communication is fail
C3P0 documentation
Set up c3p0.properties in root of classpath
acquireRetryAttempts=1
As MJB says, setting c3p0's config parameter acquireRetryAttempts to 1 will cause clients to merely experience an Exception on a Connection acquisition failure rather than waiting and retrying.
If you wish for a c3p0 Connection pool to nevermore attempt to Connect to the database after a round of acquisition failures (with a "round" being defined by acquireRetryAttempts), set the config parameter breakAfterAcquireFailure to true. (By default this is false, c3p0 will try again to acquire Connections when new clients come calling.)
http://www.mchange.com/projects/c3p0/#acquireRetryAttempts
http://www.mchange.com/projects/c3p0/#breakAfterAcquireFailure
Related
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.
We have a Spring Boot Micro-services Architecture, the problem is the connections in pool sometimes become stale and a /health check fail, This is how I am going to address the issue, by setting testOnBorrow so that connection is tested before being returned.
Following properties should eventually fix the problem
spring.datasource.tomcat.testOnBorrow=true
spring.datasource.tomcat.validationQuery=SELECT 1
spring.datasource.tomcat.validationInterval=30000
spring.datasource.tomcat.testWhileIdle = true
spring.datasource.tomcat.timeBetweenEvictionRunsMillis=30000
spring.datasource.tomcat.minEvictableIdleTimeMillis=60000
spring.datasource.tomcat.validationQuery = SELECT 1
I am trying to make sure all this happening right, before I promote this change.
I don't see SELECT 1 in any logs even the connection is Idle for a long time.
So there are 2 questions:
Is there a way to see the validation query executed at certain times in java logs / db logs so that it ensures the problem is fixed.
What should be the optimal settings for connection validation for testOnBorrow (validationInterval) and testWhileIdle (timeBetweenEvictionRunsMillis) as mentioned in Tomcat JDBC Connection Pool Documentation
We are using MySQL database along with C3P0ComboPooledDataSource for pooling. Below are the configuration:
minPoolSize=10
maxPoolSize=50
maxStatements=50
idleConnectionTestPeriod=3600
acquireIncrement=5
maxIdleTime=600
numHelperThreads=6
unreturnedConnectionTimeout=3600
maxIdleTimeExcessConnections=600
As per document after maxIdleTime the connection should close automatically, and this happens when we debug locally. But on production server we see the MySQL connection count (show processlist) exceeds more than 50 and they are in sleep mode from last 2400 seconds, ideally which should get closed after 600 seconds.Due to this the application is not able to establish connection through pooled data source as it exceeds maxPoolSize. Please let me know what can be done in order to debug this and how can we resolve it.
This is almost certainly a Connection leak. Please be sure to reliably close your Connections, ideally using something like the try-with-resources.
If you don't understand where your application is not reliably closing Connnections See e.g. C3P0 Spring Hibernate: Pool maxed out. How to debug?
I've an application that uses Spring+Hibernate+C3P0 as the connection pool. If I start the application and the database is down, Tomcat hangs for a long log time withouth giving any feedback. Is there some property that I can set to avoid this? For example, if after 30 seconds it can't get a connection, throw a connection timeout exception.
By default, it should take about 30 seconds before c3p0 signals a failure if it cannot acquire a Connection. You can control the length of time by modifying either the number of attempts c3p0 makes at the database or the interval between attempts.
See c3p0.acquireRetryAttempts and c3p0.acquireRetryDelay.
If you set c3p0.acquireRetryAttempts to one, c3p0 won't retry and connection attempts will fail retry immediately.
See also Configuring Recovery From Database Outages.
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.