c3p0 database pool errors
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
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
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?
精彩评论