Cannot get a connection, pool error Timeout waiting for idle object

 2012-12-21 13:35:40,812 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool error Timeout waiting for idle object


数据库保存的时候发生这个错误:

源码如下:


protected void executeInternal() {		
		List<AttackEvent> aeList = attackMontorDAO.findHalfAnHour();
		Date date = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
		String stime = formatter.format(date);
		int hous = date.getHours() - 1;
		date.setHours(hous);
		String etime = formatter.format(date);
			for (int i = 0; i < aeList.size(); i++) {
				AttackEventCount atec = new AttackEventCount();
				AttackEvent ar = aeList.get(i);
				String sip = ar.getAttackerIp();
				int sport = ar.getAttackerPort();
				String eip = ar.getVictimIp();
				int eport = ar.getVictimPort();
				String potoc = ar.getProtocol();
				int centerId = ar.getCenterId();
				Object object = attackMontorDAO.checkCount(sip, sport, eip,
						eport, potoc, stime, etime, centerId);//注意这里,我的问题是这里的
				Object[] obj = (Object[]) object;
				BigDecimal count;
				Timestamp max;
				Timestamp min;
				if (obj.length == 0) {
					continue;
				} else {
					count = (BigDecimal) obj[0];
					max = (Timestamp) obj[1];
					min = (Timestamp) obj[2];
				}
				atec.setStartIP(sip);
				atec.setStartPort(sport);
				atec.setEndIP(eip);
				atec.setEndPort(eport);
				atec.setProtocol(potoc);
				atec.setStartTime(min);
				atec.setEndTime(max);
				String str = count.toString();
				atec.setCenterId(centerId);
				atec.setCount(Integer.parseInt(str));
				attackEventCountDAO.save(atec);
				System.out.println("同步攻击事件任务结束");
		}

	}

这是action中的方法,循环list进行组装数据,当保存53条的时候报错,连接不够用,获取不到连接。修改连接池数量,可以解决问题。但是不实际。如果数据超过几十万呢?是不是开几十万的连接?

各种查找各种修改都不行。最后发现是上面标注的dao里的问题

session.flush();
		session.clear();
		session.close();

在查询sql执行完后放弃链接。之后在没出过问题。

网上的事务管理什么的都有关系。建议认真的查找,或者塞假数据测试


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值