日期:2014-05-20  浏览次数:20763 次

struts2+ireport,多次下载后没有响应的问题.
//导出ireport pdf文件报表. 能够正常运行
//path irepot有效路径,下载name文件名,params参数,con数据库连接.list以后用的bean.
public String pdf(String path,String name,Map params,Connection con,List list) throws JRException, IOException, SQLException{
ServletContext context = request.getSession().getServletContext();
response.setCharacterEncoding("UTF-8");
response.setContentType("application/ms-download");
response.setHeader("Content-disposition","attachment; filename=" + URLEncoder.encode(String.valueOf(name), "UTF-8") + ".pdf");
//response.setContentType("application/pdf");
 
System.out.println(path);//
Map imageMap = new HashMap();
//Connection con = repDatereportManager.getConnect();
Statement stmt = con.createStatement();
request.getSession().setAttribute( "IMAGES_MAP" , imageMap);
JasperReport jasperReport = (JasperReport)JRLoader.loadObjectFromLocation(path);
JasperPrint print = JasperFillManager.fillReport(jasperReport,params,con);
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
//ServletOutputStream ouputStream = response.getOutputStream(); 
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
exporter.exportReport();
con.close();
stmt.close();
// ouputStream.flush(); 这个在别的地方做处理了.
// ouputStream.close();
return null;
}
现在发现问题是,开始下载两三次是正常的,能够正的导出pdf文件,产生报表.但是如果多下载几次,比如6次10次的就会引struts2的无响应的情况,造成整web服务瘫痪.运行到.
public String intercept(ActionInvocation invocation) throws Exception {
.....
String result = invocation.invoke();//到这里就不动了不响应了,这里是核心调度啊,
  //把请求分配到各个Action中去啊.不知道什么问题,到这里就不运行了,外部请求还是可以远行到这里的.
return result;
}
开始以为是ouputStream的问题,发现和tomcat是没有关系的.tomcat是正常运行的.就是struts2的机制不起作用了,查来查去没有找到什么原因,不报错,就是不响应了,纠结.不知道哪位大神有碰到类似的问题或有什么解决思路的.帮帮忙吧.

------解决方案--------------------
帮顶一下,祝楼主好运
------解决方案--------------------
我遇过类式的问题一般出这问题有如下可能
1.线程太多 线程池执行不过来

2.hiberante session 打开太多没有关闭 (上次我就是这个)

3.线程死锁