c3p0 数据库池错误

发布于 2024-09-10 20:43:39 字数 1298 浏览 8 评论 0原文

当我的程序使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叶落知秋 2024-09-17 20:43:39

使用 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

尽揽少女心 2024-09-17 20:43:39

此论坛帖子可能对您有帮助: 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文