关闭是及时的.问题出在<house-keeping-sleep-time>90000</house-keeping-sleep-time>连接池的这个地方,90000太小了.我该成很大就可以,这个循环执行时间很长. 我也改了代码,将查询操作进行了封装. 我认为不需要调大<house-keeping-sleep-time>这个标签的参数了,但是还是要调很大.这个标签不是 proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁.可是我每次操作都重新获得连接,一次查询语句的时间很短啊,怎么还是会获取不到啊public class CompareFundDAO extends BaseHibernateDAO { private static final Log log = LogFactory.getLog(TbSourceDAO.class);
@SuppressWarnings("unchecked") public List<CompareFund> getCompareResult(String month){
try{ List list = new ArrayList<CompareFund>(); TbBankStaticsDAO bankStaticsDAO = new TbBankStaticsDAO(); List baklist = bankStaticsDAO.findStaticRecord("", month); if(baklist == null || baklist.size()==0){ log.error("没有这个月的数据"); return null; } Iterator it = baklist.iterator();
String where = "qymc not like '%测试%' and qymc not like '%hxtest%' and qymc not like '%zjca%' and qymc not like '%浙江ca%' and dqzt = '新领' and status > 0 and"; String hql1 = "select count(*)*500 from TbHx where "+where+" dqxzh = ? and indate <= to_date(?,'yyyy-MM-dd') and indate >= to_date(?,'yyyy-MM-dd')"; String hql2 = "select count(*)*500 from TbHx where "+where+" dqxzh = ? ";
还有 maxWait设定最大的连接等待时间,如果超过此时间将连接到异常
private static final Log log = LogFactory.getLog(TbSourceDAO.class);
@SuppressWarnings("unchecked")
public List<CompareFund> getCompareResult(String month){
try{
List list = new ArrayList<CompareFund>();
TbBankStaticsDAO bankStaticsDAO = new TbBankStaticsDAO();
List baklist = bankStaticsDAO.findStaticRecord("", month);
if(baklist == null || baklist.size()==0){
log.error("没有这个月的数据");
return null;
}
Iterator it = baklist.iterator();
String where = "qymc not like '%测试%' and qymc not like '%hxtest%' and qymc not like '%zjca%' and qymc not like '%浙江ca%' and dqzt = '新领' and status > 0 and";
String hql1 = "select count(*)*500 from TbHx where "+where+" dqxzh = ? and indate <= to_date(?,'yyyy-MM-dd') and indate >= to_date(?,'yyyy-MM-dd')";
String hql2 = "select count(*)*500 from TbHx where "+where+" dqxzh = ? ";
while(it.hasNext()){
TbBankStatics bankStatics = (TbBankStatics)it.next();
CompareFund compareFund = new CompareFund();
compareFund.setRaName(bankStatics.getTbRajg().getRaName());
compareFund.setIndate(bankStatics.getIndate());
compareFund.setIndateb(bankStatics.getIndateb());
compareFund.setAllmoney(bankStatics.getAllsum());
compareFund.setMonthmoney(bankStatics.getMonthmoney()+bankStatics.getMonthjust());
compareFund.setYearmoney(bankStatics.getYearmoney());
Double monthys = getYs(hql1, bankStatics, 1);
compareFund.setMonthys(monthys);
Double yearys = getYs(hql1, bankStatics, 2);
compareFund.setYearys(yearys);
Double allys = getYs(hql2, bankStatics, 3);
compareFund.setAllys(allys);
compareFund.setAllmargin(allys-bankStatics.getAllsum());
compareFund.setYearmargin(yearys-bankStatics.getYearmoney());
compareFund.setMonthmargin(monthys-bankStatics.getMonthmoney()-bankStatics.getMonthjust());
list.add(compareFund);
}
return list;
}catch(RuntimeException re){
throw re;
}
}
public Double getYs(String hql,TbBankStatics bankStatics,int choose){
Session session = null;
System.out.println(bankStatics.getIndate()+"|"+bankStatics.getIndateb()+"|"+bankStatics.getTbRajg().getRaId());
try {
session = getSession();
Query q = session.createQuery(hql);
q.setString(0, bankStatics.getTbRajg().getRaId());
if(choose==1){
q.setString(1, DataUntil.getDateFormat(bankStatics.getIndate(),"yyyy-MM-dd"));
q.setString(2, DataUntil.getDateFormat(bankStatics.getIndateb(),"yyyy-MM-dd"));
}
else if(choose==2){
Calendar calendar = Calendar.getInstance();
calendar.setTime(bankStatics.getIndateb());
calendar.set(Calendar.MONTH,0);
calendar.set(Calendar.DAY_OF_MONTH,1);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String indate = df.format(calendar.getTime());
q.setString(1, DataUntil.getDateFormat(bankStatics.getIndate(),"yyyy-MM-dd"));
q.setString(2, indate);
}
Double money = ((Integer)q.list().get(0)).doubleValue();
return money;
}catch(RuntimeException re){
throw re;
}finally{
closeSession();
}
}
}