c3p0
c3p0 copied to clipboard
initialPoolSize configuration doen't work in tomcat
Hi, we have this configuration for our data source in tomcat 6:
Resource acquireIncrement="1" acquireRetryAttempts="2" auth="Container" debugUnreturnedConnectionStackTraces="true" description="Connessione GTA" driverClass="oracle.jdbc.driver.OracleDriver" factory="org.apache.naming.factory.BeanFactory" jdbcUrl="jdbc:oracle**" maxPoolSize="20" maxStatementsPerConnection="10" minPoolSize="5" name="jdbc/**" password="_" type="com.mchange.v2.c3p0.ComboPooledDataSource" unreturnedConnectionTimeout="180" user="_" checkoutTimeout="10" initialPoolSize="10"
When tomcat start the datasource doesn't load the initial connection (10) and the first request of getConnection throw an error for timeout (10 milliseconds). The initial pool is created after the first request.
If I use JMX to execute un hard reset the pool load the initial connections without getConnection call.
Sincerally
Claudio
hi,
so, c3p0 pools initialize lazily. if they didn't you'd churn through lots of Connections while you were setting up config (because each distinct configuration requires a separate pool as c3p0 is architected). normally the only effect of lazy initialization is a sluggish first attempt to checkout a Connection. in your case, however, you have set such a tight checkoutTimeout that, basically, calls to getConnection() fail immediately if a Connection is not immediately available for checkout.
the simplest workaround would be to set checkoutTimeout to a longer value (maybe 1000).
Hello,
If I restart a web application in high traffic, most of those first coming request will fail to checkout. For Internet applications, it's a bad experience. In worst case, even the web application will crash. In this case, most of developers, like me, may want to warm up the connection pool firstly before let it accept requests.
For now, as a workaround, I just manually call the getConnection method to initliaze the pool and close the connection immediately during the startup. I suggest that you may provide a method to create the initial connections. It depends on the user whether to call it explicitly or not .
Thanks.
Xiaofeng