1回复
3年前
从mybatis读取数据时OOM了
我在试着用 MyBatis 读取大型结果集的时候发生了 OOM。 MyBatis 版本3.5。我想遍历游标而不是加载整个查询结果。 有没有人有从 mybatis select 返回游标而不是整个结果的例子?
[java] SEVERE:Memory usage is low, parachute is non existent, your system may start failing.
[java] java.lang.OutOfMemoryError: Java heap space
[java] AsyncLogger error handling event seq=0, value='null':
[java] java.lang.OutOfMemoryError: Java heap space
[java] 06 Sep 2020 05:34:34,682 [ERROR] (http-nio-0.0.0.0-8243-ClientPoller-1) org.apache.tomcat.util.net.NioEndpoint:
[java] java.lang.OutOfMemoryError: Java heap space
[java] at java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1043) ~[?:?]
[java] at org.apache.tomcat.util.net.NioEndpoint$Poller.timeout(NioEndpoint.java:1471) ~[Bobcat-2.2.jar:?]
[java] at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:1265) ~[Bobcat-2.2.jar:?]
[java] at java.lang.Thread.run(Thread.java:834) [?:?]
ReaderDao.xml
<select id="downloadelements" resultMap="elementMap">
select *
from sample_table
where element_timestamp between #{startTime} and #{endTime}
and status=#{status}
</select>
ReaderDao.java
public interface ReaderDao {
Cursor<Element> downloadElements(final @NotNull @Param("startTime") ZonedDateTime startTime,
final @NotNull @Param("endTime") ZonedDateTime endTime,
final @NotNull @Param("status") String status);
}
Database: Aurora PostgreSQL
Cursor<Element> elementList = downloadElements(start, end, status);
Iterator<Element> elementIterator = elementList.iterator();
while (elementIterator.hasNext()) {
Element element = ElementIterator.next();
log.info(element.toString());
}
<resultMap id="elementMap" type="Element">
<constructor>
<arg javaType="String" column="status"/>
<arg javaType="java.time.ZonedDateTime" column="start_time"/>
<arg javaType="java.util.Optional" jdbcType="TIMESTAMP" column="end_time"/>
</constructor>
</resultMap>
1880 阅读