XSD(maxOccurs=(指定大值))-java.lang.OutOfMemoryError:java堆空间

XSD(maxOccurs=(指定大值))-java.lang.OutOfMemoryError:java堆空间,xsd,xerces,jaxb2,Xsd,Xerces,Jaxb2,当我们在tomcat服务器上部署应用程序时,我一直面临java.lang.OutOfMemoryError问题,因为我们为maxOccurs attributei.e指定了较大的值。架构定义中的maxOccurs=99999。请查找下面的示例代码段和异常堆栈跟踪。请有人建议优化的解决方案,以避免这种情况 最初,我们将maxoccurs值保持为unbound。但是,当我们使用HP Fortify Static code Analyzer扫描代码库时,我们发现存在一个关键问题。有关此问题的更多信息,

当我们在tomcat服务器上部署应用程序时,我一直面临java.lang.OutOfMemoryError问题,因为我们为maxOccurs attributei.e指定了较大的值。架构定义中的maxOccurs=99999。请查找下面的示例代码段和异常堆栈跟踪。请有人建议优化的解决方案,以避免这种情况

最初,我们将maxoccurs值保持为unbound。但是,当我们使用HP Fortify Static code Analyzer扫描代码库时,我们发现存在一个关键问题。有关此问题的更多信息,请访问:,在左侧面板上,我们有XML->Environment->Weak XML Schema:无限出现。因此,HP Foritfy工具建议将maxoccurs限制在合理的数量。我们必须解决这个问题,以获得业务部门的批准

Java version: JDK 1.6.0_30
Tomcat Version: 6.0                
注意:请不要建议增加堆大小。我目前面临的情况是在开发tomcat应用服务器时,在生产tomcat应用服务器时,我看不到这个问题,因为生产服务器可能有更多的空间

异常堆栈跟踪:

Caused by: java.lang.OutOfMemoryError: Java heap space
     at org.apache.xerces.impl.dtd.models.CMStateSet.<init>(Unknown Source)
     at org.apache.xerces.impl.xs.models.XSDFACM.buildDFA(Unknown Source)
     at org.apache.xerces.impl.xs.models.XSDFACM.<init>(Unknown Source)
     at org.apache.xerces.impl.xs.models.CMBuilder.createDFACM(Unknown Source)
     at org.apache.xerces.impl.xs.models.CMBuilder.getContentModel(Unknown Source)
     at org.apache.xerces.impl.xs.XSComplexTypeDecl.getContentModel(Unknown Source)
     at org.apache.xerces.impl.xs.XSConstraints.fullSchemaChecking(Unknown Source)
     at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
     at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
     at org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
     at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:594)
     at com.prac.app.common.xmlsupport.SchemaLoaderImpl.init(SchemaLoaderImpl.java:92)
     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:597)

一个简单的更改:将maxOccurs设置为unbounded,而不是一个大数字。如果验证器正在构建有限状态自动机的重量级表示,那么您当前的声明需要一百万个状态;maxOccurs=unbounded将其减少为一种状态。如果您当前的架构经常捕获由超过9999999个用户元素的文档引起的错误,那么更改为“无界”当然会削弱您的验证。

我更新了我的查询,为什么无法将maxoccurs设置为“无界”。无论如何,感谢您抽出时间来研究此问题。您是否尝试过将99999更改为99以查看这是否有帮助?您实际期望出现多少次用户?你真的能处理一百万个用户元素吗?如果是的话,无界真的对这个应用程序不安全吗?或者将maxOccurs设置为9999999是你在不考虑安全问题的情况下让强化警告消失的方法吗?
Caused by: java.lang.OutOfMemoryError: Java heap space
     at org.apache.xerces.impl.dtd.models.CMStateSet.<init>(Unknown Source)
     at org.apache.xerces.impl.xs.models.XSDFACM.buildDFA(Unknown Source)
     at org.apache.xerces.impl.xs.models.XSDFACM.<init>(Unknown Source)
     at org.apache.xerces.impl.xs.models.CMBuilder.createDFACM(Unknown Source)
     at org.apache.xerces.impl.xs.models.CMBuilder.getContentModel(Unknown Source)
     at org.apache.xerces.impl.xs.XSComplexTypeDecl.getContentModel(Unknown Source)
     at org.apache.xerces.impl.xs.XSConstraints.fullSchemaChecking(Unknown Source)
     at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
     at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
     at org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
     at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:594)
     at com.prac.app.common.xmlsupport.SchemaLoaderImpl.init(SchemaLoaderImpl.java:92)
     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:597)