c3p0数据源设置不管用,总出现超时连接没法释放
jdbc.maxPoolSize=100
jdbc.minPoolSize=2
jdbc.initialPoolSize=2
jdbc.acquireIncrement=2
jdbc.maxStatements=1000
jdbc.maxIdleTime=300
jdbc.checkoutTimeout=5000
jdbc.maxConnectionAge=500
这是我的设置
---------------------------------------------------------------------
private final static Log log = LogFactory.getLog(DataSourceManager.class);
private final static ThreadLocal<Connection> conns = new ThreadLocal<Connection>();
private static DataSource dataSource;
private static boolean show_sql = false;
初始化代码:
try {
if (dbProperties == null) {
dbProperties = new Properties();
dbProperties.load(DataSourceManager.class
.getResourceAsStream("db.properties"));
}
Properties cp_props = new Properties();
for (Object key : dbProperties.keySet()) {
String skey = (String) key;
if (skey.startsWith("jdbc.")) {
String name = skey.substring(5);
cp_props.put(name, dbProperties.getProperty(skey));
if ("show_sql".equalsIgnoreCase(name)) {
show_sql = "true".equalsIgnoreCase(dbProperties
.getProperty(skey));
}
}
}
dataSource = (DataSource) Class.forName(
cp_props.getProperty("datasource")).newInstance();
if (dataSource.getClass().getName().indexOf("c3p0") > 0) {
// Disable JMX in C3P0
System.setProperty(
"com.mchange.v2.c3p0.management.ManagementCoordinator",
"com.mchange.v2.c3p0.management.NullManagementCoordinator");
}
log.info("Using DataSource : " + dataSource.getClass().getName());
BeanUtils.populate(dataSource, cp_props);
Connection conn = getConnection();
DatabaseMetaData mdm = conn.getMetaData();
log.info("Connected to " + mdm.getDatabaseProductName() + " "
+ mdm.getDatabaseProductVersion());
closeConnection();
} catch (Exception e) {
// throw new DBException(e);
}
昨天监控到现在。。发现有4个超时的连接,都是1万多秒的
这种连接应该是属于泄漏了把。。想问下为什么C3p0的设置不起效?我设置了maxConnectionAge也没看到起效。。