c3p0 数据库池错误
当我的程序使用 3cp0 作为连接池运行 30 分钟左右后,我收到以下异常。
这是错误:
[java] INFO [Timer-0] (BasicResourcePool.java:1392) - A checked-out resource is overdue, and will be destroyed: com.mchange.v2.c3p0.impl.NewPooledConnection@eaecb09
[java] The last packet successfully received from the server was 375,017 milliseconds ago. The last packet sent successfully to the server was 9 milliseconds ago.
[java] Exception in thread "main" java.lang.NullPointerException
[java] at com.mytest.myorg.MyProg.MyProgRunner.main(MyProgRunner.java:104)
我正在像这样设置我的池:
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass( "com.mysql.jdbc.Driver" ); //loads the jdbc driver
cpds.setJdbcUrl( "jdbc:mysql://"+hostname+"/"+database );
cpds.setUser(username);
cpds.setPassword(password);
cpds.setMinPoolSize(5);
cpds.setAcquireIncrement(5);
cpds.setMaxPoolSize(15);
cpds.setAutoCommitOnClose(true);
cpds.setIdleConnectionTestPeriod(300);
cpds.setMaxStatements(180);
cpds.setNumHelperThreads(20);
cpds.setUnreturnedConnectionTimeout(300);
我有 100 个线程来抓取页面,然后有 15 个数据库线程将结果插入到我的数据库中。如果爬网任务花费超过 20 秒,我会终止该线程。有什么想法为什么数据库连接池会死掉吗?
谢谢
I'm getting the following exception after my program runs for 30 minutes or so with 3cp0 as my connection pool.
here's the error:
[java] INFO [Timer-0] (BasicResourcePool.java:1392) - A checked-out resource is overdue, and will be destroyed: com.mchange.v2.c3p0.impl.NewPooledConnection@eaecb09
[java] The last packet successfully received from the server was 375,017 milliseconds ago. The last packet sent successfully to the server was 9 milliseconds ago.
[java] Exception in thread "main" java.lang.NullPointerException
[java] at com.mytest.myorg.MyProg.MyProgRunner.main(MyProgRunner.java:104)
and I'm setting up my pool like this:
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass( "com.mysql.jdbc.Driver" ); //loads the jdbc driver
cpds.setJdbcUrl( "jdbc:mysql://"+hostname+"/"+database );
cpds.setUser(username);
cpds.setPassword(password);
cpds.setMinPoolSize(5);
cpds.setAcquireIncrement(5);
cpds.setMaxPoolSize(15);
cpds.setAutoCommitOnClose(true);
cpds.setIdleConnectionTestPeriod(300);
cpds.setMaxStatements(180);
cpds.setNumHelperThreads(20);
cpds.setUnreturnedConnectionTimeout(300);
I have 100 threads that crawl a page then 15 DB threads that insert the results into my database. If a crawl task takes over 20 seconds I kill the thread. Any ideas why the db connection pool just dies?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 c3p0 时,您需要在 c3p0.properties 文件中初始化一些属性。
其中有一个名为 c3p0.unreturnedConnectionTimeout 的属性。
它的值以秒为单位。如果某些查询未在指定时间段内返回结果(如您在 c3p0.properties 文件中为 c3p0.unreturnedConnectionTimeout 属性指定的那样),则当前会话将被销毁,并且新会话将从会话池中拉出,但您的代码正在运行之前的会话已被销毁。因此,您的代码会抛出会话已关闭异常,
因此您必须找出查询可能花费的最长时间,并根据该时间设置此属性值。
干杯
While using c3p0, there are some properties that you need to initialize in c3p0.properties file.
Out of them there is one property named c3p0.unreturnedConnectionTimeout.
Its value is in seconds. If some query did not return result within specified time period (as you specified for c3p0.unreturnedConnectionTimeout property in c3p0.properties file), then current session will be destroyed and new session will be pulled out from session pool, but your code is working on previous session that is already destroyed. So your code throws session is alredy closed Exception
So You have to find out max time that your query might take and set this property value according to that.
Cheers
此论坛帖子可能对您有帮助: http: //old.nabble.com/A-checked-out-resource-is-overdue--td20545738.html#a20575081
在被杀死的线程的情况下,连接是否返回到池中?
this forum posting might help you: http://old.nabble.com/A-checked-out-resource-is-overdue--td20545738.html#a20575081
In the case of the killed threads, are the connections returned to the pool?