使用JAXB在XML中对大量对象进行封送处理时出现内存问题

时间:2016-04-04 09:48:41

标签: java xml jaxb

我正在获取 java.lang.OutOfMemoryError:Java堆空间在将大量对象传递给XML时遇到异常,但是之前我使用的是较少的对象或较少的xml文件大小时JAXB marshaller.marshal(消息,fi); 绝对没问题。现在根据我项目中的新要求,我们需要增加XML文件中的数据,我根据新故事调整逻辑。 然而,经过调整逻辑后,我运行报告,在开始抛出OOM异常后,它看起来很好2-3次。

注意:我增加了Xms,Xmx和XX:MaxPermSize,但仍面临同样的问题。

请你帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

The java.lang.OutOfMemoryError: Java heap space is commonly caused when the JVM runs out of heap space.

This can be mainly due to two reasons

1. Memory leak
2. excessive computation by the app

In your case i assume its the second one causing the problem. This can be solved by setting the Xmx value to a larger value than the current one.

If you are using tomcat you can do this in the setenv.sh inside tomcat bin. setting CATALINA_OPTS=Xmx1024M (or any other value)