mybatis拼接sql导致的oom报错 GC报错

报错1:mybatis拼接过多

java 复制代码
java.lang.OutOfMemoryError: GC overhead limit exceeded

具体报错:

java 复制代码
nested exception is org.apache.ibatis.builder.BuilderException:
Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfWhere'.
Cause: org.apache.ibatis.ognl.OgnlException: 
sqlSegment [java.lang.OutOfMemoryError: GC overhead limit exceeded

一看报错内容,有builder,expression,sqlSegment,ognl,就可以推测出,应该是mybatis拼接条件太多,导致内存超了。例如条件in里,code太多,或者id太多。

oracle官方对 java.lang.OutOfMemoryError: GC overhead limit exceeded 解释如下:

java 复制代码
Exception in thread thread_name: 
java.lang.OutOfMemoryError: GC Overhead limit exceeded Cause: 
The detail message "GC overhead limit exceeded" indicates that 
the garbage collector is running all the time 
and Java program is making very slow progress. 
After a garbage collection, 
if the Java process is spending more than approximately 98% of its time doing garbage collection 
and if it is recovering less than 2% of the heap 
and has been doing so far the last 5 (compile time constant) consecutive garbage collections, 
then a java.lang.OutOfMemoryError is thrown. 
This exception is typically thrown 
because the amount of live data barely fits into the Java heap having little free space for new allocations.
 
Action: Increase the heap size. 
The java.lang.OutOfMemoryError exception for GC Overhead limit exceeded can be turned off with the command line flag -XX:-UseGCOverheadLimit.

大致意思是说:

频繁的进行内存回收(最起码已经进行了5次连续的垃圾回收),JVM就会曝出java.lang.OutOfMemoryError: GC overhead limit exceeded错误。

解决的办法是:

增加堆大小,启动脚本添加参数-Xmx1024m。

或者 关闭GC Overhead limit:-XX:-UseGCOverheadLimit

但由于这是代码本身引起,而非内存不够的问题。所以不建议去改动堆参数或者关闭GC上限。

具体参考

BuilderException OgnlException sqlSegment nonEmptyOfWher OutOfMemoryError:GC overhead limit exceeded_globalcoding的博客-CSDN博客

报错2:

占位符

===================分割线=======================

文章到此已经结束,以下是紫薯补丁

java.lang.OutOfMemoryError: GC overhead limit exceeded

nested exception is org.apache.ibatis.builder.BuilderException:

Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfWhere'.

Cause: org.apache.ibatis.ognl.OgnlException:

sqlSegment [java.lang.OutOfMemoryError: GC overhead limit exceeded

Exception in thread thread_name:

java.lang.OutOfMemoryError: GC Overhead limit exceeded Cause:

The detail message "GC overhead limit exceeded" indicates that

the garbage collector is running all the time

and Java program is making very slow progress.

After a garbage collection,

if the Java process is spending more than approximately 98% of its time doing garbage collection

and if it is recovering less than 2% of the heap

and has been doing so far the last 5 (compile time constant) consecutive garbage collections,

then a java.lang.OutOfMemoryError is thrown.

This exception is typically thrown

because the amount of live data barely fits into the Java heap having little free space for new allocations.

Action: Increase the heap size.

The java.lang.OutOfMemoryError exception for GC Overhead limit exceeded can be turned off with the command line flag -XX:-UseGCOverheadLimit.

相关推荐
Java小白笔记5 小时前
关于使用Mybatis-Plus 自动填充功能失效问题
spring boot·后端·mybatis
计算机学姐9 小时前
基于SpringBoot+Vue的篮球馆会员信息管理系统
java·vue.js·spring boot·后端·mysql·spring·mybatis
程序员大金9 小时前
基于SpringBoot+Vue+MySQL的智能物流管理系统
java·javascript·vue.js·spring boot·后端·mysql·mybatis
惜.己14 小时前
MyBatis中一对多关系的两种处理方法
java·开发语言·后端·sql·mysql·mybatis·idea
终末圆14 小时前
MyBatis动态SQL中的`if`标签使用【后端 19】
java·数据结构·数据库·sql·算法·spring·mybatis
飞翔的佩奇15 小时前
Java项目: 基于SpringBoot+mybatis+maven医院管理系统(含源码+数据库+任务书+开题报告+毕业论文)
java·数据库·spring boot·毕业设计·maven·mybatis·医院管理系统
这孩子叫逆16 小时前
35. MyBatis中的缓存失效机制是如何工作的?
java·spring·mybatis
ChinaRainbowSea18 小时前
十八,Spring Boot 整合 MyBatis-Plus 的详细配置
java·数据库·spring boot·spring·mybatis·web
飞翔的佩奇1 天前
Java项目: 基于SpringBoot+mybatis+maven课程答疑系统(含源码+数据库+毕业论文)
java·数据库·spring boot·毕业设计·maven·mybatis·课程答疑
OceanSky61 天前
Mybatis中sql数组为空判断
数据库·sql·mybatis·数组判空