使用dbutils的BeanListHandler 处理10W条数据, 报内存溢出

金河 发布于 2011/08/08 16:13
阅读 2K+
收藏 0
代码调用如下:
agentList=runner.query(CommonDAO.getConnection(), 
    sql.toString(), 
    new BeanListHandler<Agent>(Agent.class), 
    params.toArray()); 
错误信息:
java.lang.OutOfMemoryError: Java heap space
at java.nio.ByteBuffer.wrap(ByteBuffer.java:350)
at java.lang.StringCoding$CharsetSD.decode(StringCoding.java:187)
at java.lang.StringCoding.decode(StringCoding.java:228)
at java.lang.String.<init>(String.java:405)
at java.lang.String.<init>(String.java:433)
at com.mysql.jdbc.ResultSet.getStringInternal(ResultSet.java:5674)
at com.mysql.jdbc.ResultSet.getString(ResultSet.java:5544)
at com.mysql.jdbc.ResultSet.getObject(ResultSet.java:4933)
at org.apache.commons.dbutils.BeanProcessor.processColumn(BeanProcessor.java:443)
at org.apache.commons.dbutils.BeanProcessor.createBean(BeanProcessor.java:204)
at org.apache.commons.dbutils.BeanProcessor.toBeanList(BeanProcessor.java:173)
at org.apache.commons.dbutils.BasicRowProcessor.toBeanList(BasicRowProcessor.java:134)
at org.apache.commons.dbutils.handlers.BeanListHandler.handle(BeanListHandler.java:81)
at org.apache.commons.dbutils.handlers.BeanListHandler.handle(BeanListHandler.java:33)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:396)
at com.todgo.tmp.dao.impl.AgentDAOImpl.getList(AgentDAOImpl.java:77)
at com.todgo.tmp.service.impl.AgentServiceImpl.getAgentList(AgentServiceImpl.java:44)
at com.todgo.tmp.action.AgentAction.exportData(AgentAction.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
网上关于dbutils的资料甚少, 恳请各位解答.
加载中
0
dargoner
dargoner
没法解决,哪有加载这么多bean的,加内存都没用,并发下死翘翘,为啥不能分页呢,或者分段取呢
0
红薯
红薯
一次处理那么大的数据量,除了加大虚拟机内存外,要避免一次性读取那么多记录。
0
金河
金河

谢谢, 编辑了下样式. 

谢谢各位的回答, 我已经明白了. 

也就是说不是我的代码或者是DbUtils的问题, 而是数据量太大了, 应该要避免, 对吧?

我现在做的是数据导出, 所以数据量才那么大.  谢谢两位的回答, 我会限制导出的数据量, 不让他溢出. 

0
Ken5233
Ken5233
哈哈 长学问了
返回顶部
顶部