日期:2014-05-16 浏览次数:20541 次
使用c3p0,偶尔会报异常:
ERROR Thread-4 com.feedsky.dao.AbstractMutiDbDAO - 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:1913) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665) at com.mysql.jdbc.Connection.execSQL(Connection.java:3170) at com.mysql.jdbc.Connection.execSQL(Connection.java:3099) at com.mysql.jdbc.Statement.executeQuery(Statement.java:1169) at com.mchange.v2.c3p0.impl.NewProxyStatement.executeQuery(NewProxyStatement.java:35) at com.feedsky.dao.AbstractMutiDbDAO.findBySQL(AbstractMutiDbDAO.java:34) at com.feedsky.dao.impl.SrcItemDAOImpl.findBySQL(SrcItemDAOImpl.java:326) at com.feedsky.dao.impl.SrcItemDAOImpl.loadByItemUuid(SrcItemDAOImpl.java:255) at com.feedsky.service.impl.SrcItemServiceImpl.loadByItemUuid(SrcItemServiceImpl.java:37) at com.feedsky.controller.SrcFeedController.saveSrcFeed(SrcFeedController.java:97) at com.feedsky.work.SrcStoreThread.saveSrcFeed(SrcStoreThread.java:174) at com.feedsky.work.SrcStoreThread.run(SrcStoreThread.java:53) at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:748) at java.lang.Thread.run(Thread.java:619) ** END NESTED EXCEPTION ** Last packet sent to the server was 176 ms ago. 2008-02-18 10:52:53 ERROR Thread-4 com.feedsky.work.SrcStoreThread - java.lang.NullPointerException 2008-02-18 10:52:53 INFO Thread-2 com.feedsky.dao.impl.SrcItemDAOImpl - 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:1913) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665) at com.mysql.jdbc.Connection.execSQL(Connection.java:3170) at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1316) at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1235) at com.mchange.v2.c3p0.impl.NewProxyStatement.executeUpdate(NewProxyStatement.java:64) at com.feedsky.dao.impl.SrcItemDAOImpl.insert(SrcItemDAOImpl.java:178) at com.feedsky.service.impl.SrcItemServiceImpl.save(SrcItemServiceImpl.java:29) at com.feedsky.controller.SrcFeedController.saveSrcFeed(SrcFeedController.java:111) at com.feedsky.work.SrcStoreThread.saveSrcFeed(SrcStoreThread.java:174) at com.feedsky.work.SrcStoreThread.run(SrcStoreThread.java:53) at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:748) at java.lang.Thread.run(Thread.java:619) ** END NESTED EXCEPTION **
?在google和javaeye搜索了下,做了如下处理,但是还是会报错。
public synchronized static DataSource createDataSource(String driver,String url,String username,String password) throws SQLException, ClassNotFoundException { Class.forName(driver); DataSource ds_unpooled = DataSources.unpooledDataSource(url,username,password); Map overrides = new HashMap(); //当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 overrides.put("acquireIncrement", 5); overrides.put("minPoolSize", 5); overrides.put("maxPoolSize", 10); //overrides.put("initialPoolSize",cfg.getMaxPoolSize()); overrides.put