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执行完后放弃链接。之后在没出过问题。
网上的事务管理什么的都有关系。建议认真的查找,或者塞假数据测试