_鬼火冒
2013-05-09 02:34
采纳率: 100%
浏览 5.5k
已采纳

导出 大量数据内存溢出,

在 本机上用eclipse导出一百多万的数据导出,没有问题,但是部署在应用服务器上就会内存溢出,而且我把本机的tomcat也拷贝过去了。其它一个功能,比这数据还多几W,只不过少写出了几个字段,也能正常导出。

int totalSize = behaviorPortraitService.querySiletUserPortraitCountMonth(sietUserPortraitForm.getParams());
                 int pageNum = 0;
                   if (totalSize % 1000000 == 0) {
                       pageNum = totalSize / 1000000;
                   }else{
                       pageNum = totalSize / 1000000 + 1;
                   }

                write.append("        年/月                      IMSI                 手机号码           沉默天数      开卡时间"
                        + enter);
                outSTr = response.getOutputStream(); // 建立
                buff = new BufferedOutputStream(outSTr);
                // 循环总页数,得到每页的页数
                for (int i = 1; i <= pageNum; i++) {
                    // 根据页数,得到 PageResult对象
                    list = behaviorPortraitService.exportSiletUserPortraitMonth(sietUserPortraitForm.getParams(),i,100000);
                    // 循环List集合进行写入
                    for (int j = 0; j < list.size(); j++) {
                        // 循环集合,写入数据到TXT中
                        write.append(list.get(j).getBegin_endtime());
                        write.append("  " + list.get(j).getImsi());
                        write.append("  " + list.get(j).getMsisdn());
                        write.append("  "+ list.get(j).getSilencedays());
                        write.append("  " + list.get(j).getStarttime()
                                + enter);
                    }
                    // 写完一个分页对象之后,清空List,清楚缓存
                    list.clear();
                    System.gc();
                }

            buff.write(write.toString().getBytes("UTF-8"));

错误信息:

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.OutOfMemoryError: Java heap space
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:839)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    com.trajectory.manager.controller.filter.SessionPrivaligeFilter.doFilter(SessionPrivaligeFilter.java:79)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)


root cause 

java.lang.OutOfMemoryError: Java heap space
    java.lang.StringCoding$StringEncoder.encode(StringCoding.java:232)
    java.lang.StringCoding.encode(StringCoding.java:272)
    java.lang.String.getBytes(String.java:946)
    com.trajectory.behaviorportrait.controller.ExportSiletUserPortraitController.writeWeekTxtWeek(ExportSiletUserPortraitController.java:209)
    com.trajectory.behaviorportrait.controller.ExportSiletUserPortraitController.handleRequestInternal(ExportSiletUserPortraitController.java:69)
    org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    com.trajectory.manager.controller.filter.SessionPrivaligeFilter.doFilter(SessionPrivaligeFilter.java:79)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新