java spring c3p0 jdbc 怎么循环插入几十次就挂了
java spring c3p0 jdbc 怎么循环插入几十次就挂了
是不是没释放连接
报错好像是连接过多,应该怎么处理
package com.tuzuan.test.dao;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.tuzuan.dao.FileTuZuanDao;
import com.tuzuan.model.FileTuZuan;
public class FileTuZuanDaoImplTest {
private ApplicationContext ctx = null;
private FileTuZuanDao fileTuZuanDao;
{
ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
fileTuZuanDao = (FileTuZuanDao) ctx.getBean("fileTuZuanDao");
}
@Test
public void testSave() {
for (int i = 0; i < 1000; i++) {
FileTuZuan fileTuZuan = new FileTuZuan("jpg", "7fd8c3b7d493a53435e6f2a459b4a9e0", "a226e30887c65aa124939d5b1fdfcff3", 100, 500, "/file_tuzuan/2014/11/19", "jpg", "m_96e753bfb781000001ff20c498e0 - 副本 (4).jpg", 12541, 1416381592, 0);
int fileId = fileTuZuanDao.save(fileTuZuan);
System.out.println(fileId);
}
}
}
警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@2c21ac2a -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"
at sun.reflect.GeneratedConstructorAccessor13.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
at com.mysql.jdbc.Util.getInstance(Util.java:360)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1037)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2234)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
at sun.reflect.GeneratedConstructorAccessor11.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
已经提示的很明显了:Data source rejected establishment of connection, message from server: "Too many connections"
1,增大连接池链接上限;
2,增大数据库连接上限;
3,使用后的链接及时释放。
同ls
连接没释放的可能性比较大,建议你看下datasource的状态就一清二楚。
你可以把"applicationContext.xml" 贴出来, 看看你的dataSource bean是怎么定义的