I am developing a web application with database access using Spring, JDBCTemplate and c3p0.
I often have a server freeze, and I am pretty sure it comes from the number of busy database connections. If I watch the application behavior, using jconsole, I can see that the maxPoolSize of the ComboPooledDataSource is reached, and the server doesn't load a page anymore.
Here is the useful code:
DataSource definition:
<Resource auth="Container" description="GDLWeb DB Connection"
driverClass="org.postgresql.Driver"
maxPoolSize="16"
minPoolSize="1"
acquireIncrement="1"
maxIdleTime="60"
maxStatements="0"
idleConnectionTestPeriod="1800"
acquireRetryAttempts="30"
breakAfterAcquireFailure="true"
name="jdbc/gdlweb"
user="gdlweb"
password=""
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:postgresql://localhost:5432/postgres"
/>
Typical access method (in DAO class):
protected T getPersistentObject(
final String tableName,
final List<WhereClause> whereParams,
final RowMapper<T> rowMapper) {
try {
log.debug(this, "get " + tableName + " " + whereParams);
return (T) getTemplate().queryForObject(
generateSelectStar(tableName, whereParams),
extractValueMap(whereParams),
rowMapper);
} catch (final EmptyResultDataAccessException e) {
log.warning(this, "No " + tableName + " found with " + whereParams + " in the DB!");
return null;
}
}
I tried to increase the maxPoolSize to 100, which is the maxConnections defined in my postgresql server. This way, I could see that there were 43 busy connections currently openned, just before the postgresql server crashes.
I am probably using JDBCTem开发者_Go百科plate the wrong way, but I don't know where.
Thanks.
The problem may be with the Mysql Connector/J version you are using.
I had the same issue, updating to the new Mysql Connector v5.1.15 solved it for me. v5.1.13 has a bug which results in the problems you are seeing
Change-log for the version which fixes the bug: http://dev.mysql.com/doc/refman/5.1/en/cj-news-5-1-14.html
Thanks
精彩评论