NutzCN Logo
问答 批量更新老是oom,如何优化
发布于 2792天前 作者 qq_8c799e25 2185 次浏览 复制 上一个帖子 下一个帖子
标签:

老是update一个数组时发生oom,数据量最多几千个吧,java堆内存已经不能再调大了,有啥好的解决方法呢?

Caused by: java.lang.OutOfMemoryError: Java heap space
	at sun.reflect.GeneratedConstructorAccessor11.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.ResultSetImpl.getInstance(ResultSetImpl.java:319)
	at com.mysql.jdbc.MysqlIO.buildResultSetWithUpdates(MysqlIO.java:3194)
	at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:3094)
	at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:2341)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2736)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2501)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
	at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2079)
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1756)
	at com.mysql.jdbc.PreparedStatement.executeBatchInternal(PreparedStatement.java:1262)
	at com.mysql.jdbc.StatementImpl.executeBatch(StatementImpl.java:958)
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeBatch(FilterChainImpl.java:2596)
	at com.alibaba.druid.filter.FilterAdapter.statement_executeBatch(FilterAdapter.java:2474)
	at com.alibaba.druid.filter.FilterEventAdapter.statement_executeBatch(FilterEventAdapter.java:279)
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeBatch(FilterChainImpl.java:2594)
	at com.alibaba.druid.wall.WallFilter.statement_executeBatch(WallFilter.java:486)
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeBatch(FilterChainImpl.java:2594)
	at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.executeBatch(StatementProxyImpl.java:192)
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeBatch(DruidPooledPreparedStatement.java:559)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:322)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:125)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
7 回复

1000个一批

好吧,能加个带参数的update()吗

@qq_8c799e25 带什么参数

分批的大小,不然就要每个地方写循环了。
建议哈,如果麻烦就算了。

@wendal query的时候也会出oom,全部换成了软引用的方式:

		List<StockDayKline> klist = dao.query(StockDayKline.class, Cnd.where(...));
		this.kline = new SoftReference<List<StockDayKline>>(klist);

@qq_8c799e25 你需要的是dao.each方法吧

好的,这个方法我看看。
不过我这里确实需要把个股的kline全部取到,后面有对其进行二分查找的流程。

恩,多谢啦

添加回复
请先登陆
回到顶部