C3P0链接池问题 高手帮忙

qingting2016 2009-02-27 11:05:09
硬件:P43.06X2,2G内存
软件:tomcat5.5 mysql5.0 jdk1.5
链接数据库用着用着就得不到链接了,用的是jdbc链接,hibernate spring struts 都没用,每天使用者在300-350之间

mysql:my.ini
max_connections=20000

链接类:

// 连接池中连接的个数
private static final int POOL_COUNT = 400;

private static final String DB_STR = ResourceReader.getStr("db_url");

private static final String DB_DRIVER = "com.mysql.jdbc.Driver";

private static DataSource ds = null;

/**
* 初始化连接池
*
* @return
*/

public static boolean initPool() {
try {
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass(DB_DRIVER); // loads the jdbc
// driver
cpds.setJdbcUrl(DB_STR);

cpds.setMaxPoolSize(POOL_COUNT);
cpds.setMinPoolSize(25);
cpds.setInitialPoolSize(50);
cpds.setMaxIdleTime(25000);
cpds.setIdleConnectionTestPeriod(18000);
cpds.setTestConnectionOnCheckout(true);
cpds.setTestConnectionOnCheckin(true);
cpds.setMaxStatementsPerConnection(0);
ds = cpds;
Connection conn = ds.getConnection();
if (conn != null) {
conn.close();
return true;
}

} catch (Exception ex) {
LogUtil.logErr(ex);

}
return false;

}

/**
* 获得数据库连接
*
* @return
* @throws SQLException
*/
public synchronized static Connection getConnection() throws SQLException {
return ds.getConnection();
}

/**
* 关闭所有链接
*
* @param conn
* @param pstmt
* @param rs
*/
public synchronized static void closeAll(Connection conn,
PreparedStatement pstmt, ResultSet rs) {
try {
if (rs != null)
rs.close();
if (pstmt != null)
pstmt.close();
if (conn != null) {
conn.close();
}
} catch (Exception ex) {
conn = null;
LogUtil.logErr(ex);
} finally {
try {
if (pstmt != null)
pstmt.close();
if (conn != null) {
conn.close();
}
} catch (Exception ex) {
LogUtil.logErr(ex);
} finally {
try {
if (conn != null)
conn.close();
} catch (Exception ex2) {
LogUtil.logErr(ex2);
} finally {
conn = null;
}
}
}
}


异常信息:



** END NESTED EXCEPTION **



Last packet sent to the server was 0 ms ago.

STACKTRACE:

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.io.EOFException

STACKTRACE:

java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1956)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2368)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3178)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1203)
at net.btdz.oa.projectmanager.ProjectStageBaseManager.getArrayBySql(ProjectStageBaseManager.java:273)
at net.btdz.oa.projectmanager.ProjectSendAlarm.readAlarmList(ProjectSendAlarm.java:229)
at net.btdz.oa.projectmanager.ProjectSendAlarm.reloadAlarmInfo(ProjectSendAlarm.java:250)
at net.btdz.oa.projectmanager.ProjectSendAlarm.defineProc(ProjectSendAlarm.java:261)
at net.btdz.oa.common.doSQLProc.doProc(doSQLProc.java:43)
at net.btdz.oa.person.Btoa_eventFinder.doProjStageAndAlarm(Btoa_eventFinder.java:3660)
at net.btdz.oa.person.Btoa_eventFinder.findAndAlarm(Btoa_eventFinder.java:3633)
at www.seeyon.com.crimsist.other.TAlarmSchedule.doit(TAlarmSchedule.java:41)
at www.seeyon.com.crimsist.common.TOAScheduleMgr$TScheduleItem.doItem(TOAScheduleMgr.java:74)
at www.seeyon.com.crimsist.common.TOAScheduleMgr$TScheduleItem.access$100(TOAScheduleMgr.java:53)
at www.seeyon.com.crimsist.common.TOAScheduleMgr$TOAScheduleRunThread.run(TOAScheduleMgr.java:24)


** END NESTED EXCEPTION **



Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2579)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3178)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1203)
at net.btdz.oa.projectmanager.ProjectStageBaseManager.getArrayBySql(ProjectStageBaseManager.java:273)
at net.btdz.oa.projectmanager.ProjectSendAlarm.readAlarmList(ProjectSendAlarm.java:229)
at net.btdz.oa.projectmanager.ProjectSendAlarm.reloadAlarmInfo(ProjectSendAlarm.java:250)
at net.btdz.oa.projectmanager.ProjectSendAlarm.defineProc(ProjectSendAlarm.java:261)
at net.btdz.oa.common.doSQLProc.doProc(doSQLProc.java:43)
at net.btdz.oa.person.Btoa_eventFinder.doProjStageAndAlarm(Btoa_eventFinder.java:3660)
at net.btdz.oa.person.Btoa_eventFinder.findAndAlarm(Btoa_eventFinder.java:3633)
at www.seeyon.com.crimsist.other.TAlarmSchedule.doit(TAlarmSchedule.java:41)
at www.seeyon.com.crimsist.common.TOAScheduleMgr$TScheduleItem.doItem(TOAScheduleMgr.java:74)
at www.seeyon.com.crimsist.common.TOAScheduleMgr$TScheduleItem.access$100(TOAScheduleMgr.java:53)
at www.seeyon.com.crimsist.common.TOAScheduleMgr$TOAScheduleRunThread.run(TOAScheduleMgr.java:24)


** END NESTED EXCEPTION **


at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:888)
at com.mysql.jdbc.Connection.checkClosed(Connection.java:1931)
at com.mysql.jdbc.Connection.createStatement(Connection.java:3093)
at com.mysql.jdbc.Connection.createStatement(Connection.java:3075)
at www.seeyon.com.crimsist.TOAConProvider$TprvmyConnection.createStatement(TOAConProvider.java:472)
at net.btdz.oa.common.doSQLProc.doProc(doSQLProc.java:42)
at net.btdz.oa.person.Btoa_eventFinder.doAssessNodeAndAlarm(Btoa_eventFinder.java:3692)
at net.btdz.oa.person.Btoa_eventFinder.findAndAlarm(Btoa_eventFinder.java:3634)
at www.seeyon.com.crimsist.other.TAlarmSchedule.doit(TAlarmSchedule.java:41)
at www.seeyon.com.crimsist.common.TOAScheduleMgr$TScheduleItem.doItem(TOAScheduleMgr.java:74)
at www.seeyon.com.crimsist.common.TOAScheduleMgr$TScheduleItem.access$100(TOAScheduleMgr.java:53)
at www.seeyon.com.crimsist.common.TOAScheduleMgr$TOAScheduleRunThread.run(TOAScheduleMgr.java:24)


望高手帮忙解决,分不够再加,只盼解决
...全文
420 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
qingting2016 2009-03-02
  • 打赏
  • 举报
回复
等待解决
qingting2016 2009-03-01
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 fulianglove 的回复:]
IdleConnectionTestPeriod
和TestConnectionOnCheckin ,TestConnectionOnCheckin可能有冲突,
IdleConnectionTestPeriod设为18000时间太长了
这几个属性的意思你晓得吧
[/Quote]

//是不是设置了cpds.setIdleConnectionTestPeriod(18000);
TestConnectionOnCheckin ,TestConnectionOnCheckin这俩就可以不设了,实现的效果是一样的
hchen2008 2009-02-28
  • 打赏
  • 举报
回复
学习
sjqzone 2009-02-28
  • 打赏
  • 举报
回复
经查看相关资料,发现问题的原因如下: Mysql服务器默认的“wait_timeout”是8小时,如果connection空闲超过8个小时,Mysql将自动断开该 connection。在C3P0 pools中的connections如果空闲超过8小时,Mysql将其断开,而C3P0中的该connection仍然存在,如果这时有 Client请求connection,C3P0将该断开的Connection提供给Client,将会造成上面的异常。 可以这么解决该问题: 使得Connection pools中connection的lifetime与Mysql的wait_timeout时间达到一致,或者测试Connection pools中connection的有效性。 在wait_timeout的时间为8小时的情况下: C3P0增加以下配置信息: //set to 'SELECT 1' preferredTestQuery = 'SELECT 1' //set to something much less than wait_timeout, prevents connections from going stale idleConnectionTestPeriod = 18000 //set to something slightly less than wait_timeout, preventing 'stale' connections from being //handed out maxIdleTime = 25000 //if you can take the performance 'hit', set to "true" testConnectionOnCheckout = true show variables like '%timeout%'; interactive-timeout
jimeshengxian 2009-02-27
  • 打赏
  • 举报
回复
学习
qingting2016 2009-02-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fulianglove 的回复:]
Java codecpds.setIdleConnectionTestPeriod(18000);
cpds.setTestConnectionOnCheckout(true);
cpds.setTestConnectionOnCheckin(true);-------------------------------->cpds.setIdleConnectionTestPeriod(60);//cpds.setTestConnectionOnCheckout(true);//cpds.setTestConnectionOnCheckin(true);
[/Quote]

//注释掉意思是不是拿连接的时候不检查 能不能用直接拿?
cpds.setTestConnectionOnCheckin(true);-------------------------------->cpds.setIdleConnectionTestPeriod(60);//cpds.setTestConnectionOnCheckout(true);//cpds.setTestConnectionOnCheckin(true);
啥意思啊
fulianglove 2009-02-27
  • 打赏
  • 举报
回复
或者试试
automaticTestTable属性
fulianglove 2009-02-27
  • 打赏
  • 举报
回复

cpds.setIdleConnectionTestPeriod(18000);
cpds.setTestConnectionOnCheckout(true);
cpds.setTestConnectionOnCheckin(true);

-------------------------------->

cpds.setIdleConnectionTestPeriod(60);
//cpds.setTestConnectionOnCheckout(true);
//cpds.setTestConnectionOnCheckin(true);


fulianglove 2009-02-27
  • 打赏
  • 举报
回复
idleConnectionTestPeriod:隔多少秒检查所有连接池中的空闲连接,默认为0表示不检查;

testConnectionOnCheckout:因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable
等方法来提升连接测试的性能。默认为false;
testConnectionOnCheckin:如果设为true那么在取得连接的同时将校验连接的有效性。默认为false。
fulianglove 2009-02-27
  • 打赏
  • 举报
回复
IdleConnectionTestPeriod
和TestConnectionOnCheckin ,TestConnectionOnCheckin可能有冲突,
IdleConnectionTestPeriod设为18000时间太长了
这几个属性的意思你晓得吧

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧