求助,c3p0运行一段时间后无法创建新连接
检查了所有代码,所有打开的数据库连接,使用完后都做了关闭操作。我们的使用方式如下:
private static ComboPooledDataSource Myds = new ComboPooledDataSource("myds"); //use c3p0
static {
try {
System.setProperty("com.mchange.v2.c3p0.cfg.xml",ClassPath.getClassPath() + "c3p0-config.xml");
} catch (Exception e1) {
e1.printStackTrace();
}
}
//建立连接
public static Connection getConnection() {
Connection conn = null;
try {
conn = Myds.getConnection();
} catch(SQLException e){
e.printStackTrace();
}
return conn;
}
// 关闭数据库资源
public static void close(ResultSet rs, Statement st, Connection conn) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (st != null) {
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
-----------------------------------------------------
另外,Tomcat服务关闭时有“严重: The web application [/xxx] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] but has failed to stop it. This is very likely to create a memory leak.”
xxx是工程名称。
由于我们未使用spring,未能按网上说的设置 destroy-method="close" 属性。
=================
各位大侠还请多多指点,多谢!