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也没看到起效。。

解决方案 »

  1.   

    其实,我想说c3p0这个东西,bug很多。
      

  2.   

    我看过druid的介绍。觉得比较适合我现在的情况,但是配置介绍好像都是结合框架使用的。。不太清晰。。想请问下你有用过吗。。或者有没其他比较稳定的数据源可以介绍使用?
      

  3.   

    看c3p0 使用文档
    http://www.mchange.com/projects/c3p0/index.html#using_combopooleddatasource实例化的c3p0 datasource是什么?怎么实例化的?参数配置上面介绍都很详细