dom 解析器中的 java.lang.StackOverflowError
以下是我的应用程序中的许多线程将访问的方法。
public static String getXMLAsString(org.dom4j.Document dom4jDocument)
{
String strXML="";
try {
strXML = dom4jDocument.asXML();
}
catch(Exception e){
e.printStackTrace();
System.out.println("XMLUtility : General Exception :- "+e.getMessage());
}
return strXML;
}
成功执行某个线程后,会出现以下错误。
java.lang.StackOverflowError
at java.lang.String.indexOf(String.java:1352)
at org.apache.xerces.dom.ElementNSImpl.getPrefix(Unknown Source)
at org.dom4j.io.DOMReader.readElement(DOMReader.java:169)
.........................................................
.........................................................
以下是成功执行线程的上定义方法的结果
<?xml version="1.0" encoding="UTF-8"?>
<action_script>
<command>SUSPEND^
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spi="http://nsn.com/npm/SoapProvisioningInterface/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<spi:updateService>
<spi:request>
<spi:service>
<spi:serviceIdentifier>
<spi:serviceCode>CFS_Residential_v1</spi:serviceCode>
</spi:serviceIdentifier>
<spi:attributes>
<spi:attribute spi:name="CallingSystem" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">OCS</spi:value>
</spi:attribute>
<spi:attribute spi:name="MSISDN" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">{MSISDN}</spi:value>
</spi:attribute>
<spi:attribute spi:name="HSSUserAdminBlock" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:boolean">true</spi:value>
</spi:attribute>
<spi:attribute spi:name="IMSPrivateID" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">{username}</spi:value>
</spi:attribute>
</spi:attributes>
</spi:service>
</spi:request>
</spi:updateService>
</soapenv:Body>
</soapenv:Envelope>
</command>
<success_message>//ns1:updateServiceResponse</success_message>
<command>DEACTIVATE^
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spi="http://nsn.com/npm/SoapProvisioningInterface/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<spi:updateService>
<spi:request>
<spi:service>
<spi:serviceIdentifier>
<spi:serviceCode>CFS_Residential_v1</spi:serviceCode>
</spi:serviceIdentifier>
<spi:attributes>
<spi:attribute spi:name="CallingSystem" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">OCS</spi:value>
</spi:attribute>
<spi:attribute spi:name="MSISDN" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">{MSISDN}</spi:value>
</spi:attribute>
<spi:attribute spi:name="HSSUserAdminBlock" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:boolean">true</spi:value>
</spi:attribute>
<spi:attribute spi:name="IMSPrivateID" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">{username}</spi:value>
</spi:attribute>
</spi:attributes>
</spi:service>
</spi:request>
</spi:updateService>
</soapenv:Body>
</soapenv:Envelope>
</command>
<success_message>//ns1:updateServiceResponse</success_message>
<command>ACTIVATE^
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spi="http://nsn.com/npm/SoapProvisioningInterface/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<spi:updateService>
<spi:request>
<spi:service>
<spi:serviceIdentifier>
<spi:serviceCode>CFS_Residential_v1</spi:serviceCode>
</spi:serviceIdentifier>
<spi:attributes>
<spi:attribute spi:name="CallingSystem" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">OCS</spi:value>
</spi:attribute>
<spi:attribute spi:name="MSISDN" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">{MSISDN}</spi:value>
</spi:attribute>
<spi:attribute spi:name="HSSUserAdminBlock" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:boolean">false</spi:value>
</spi:attribute>
<spi:attribute spi:name="IMSPrivateID" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">{username}</spi:value>
</spi:attribute>
</spi:attributes>
</spi:service>
</spi:request>
</spi:updateService>
</soapenv:Body>
</soapenv:Envelope>
</command>
<success_message>//ns1:updateServiceResponse</success_message>
</action_script>
Following is the method that will be accessed by many threads in my application.
public static String getXMLAsString(org.dom4j.Document dom4jDocument)
{
String strXML="";
try {
strXML = dom4jDocument.asXML();
}
catch(Exception e){
e.printStackTrace();
System.out.println("XMLUtility : General Exception :- "+e.getMessage());
}
return strXML;
}
After successfully executing some thread it will give following error.
java.lang.StackOverflowError
at java.lang.String.indexOf(String.java:1352)
at org.apache.xerces.dom.ElementNSImpl.getPrefix(Unknown Source)
at org.dom4j.io.DOMReader.readElement(DOMReader.java:169)
.........................................................
.........................................................
Following is the result of upper defined method for successfully executed thread
<?xml version="1.0" encoding="UTF-8"?>
<action_script>
<command>SUSPEND^
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spi="http://nsn.com/npm/SoapProvisioningInterface/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<spi:updateService>
<spi:request>
<spi:service>
<spi:serviceIdentifier>
<spi:serviceCode>CFS_Residential_v1</spi:serviceCode>
</spi:serviceIdentifier>
<spi:attributes>
<spi:attribute spi:name="CallingSystem" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">OCS</spi:value>
</spi:attribute>
<spi:attribute spi:name="MSISDN" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">{MSISDN}</spi:value>
</spi:attribute>
<spi:attribute spi:name="HSSUserAdminBlock" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:boolean">true</spi:value>
</spi:attribute>
<spi:attribute spi:name="IMSPrivateID" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">{username}</spi:value>
</spi:attribute>
</spi:attributes>
</spi:service>
</spi:request>
</spi:updateService>
</soapenv:Body>
</soapenv:Envelope>
</command>
<success_message>//ns1:updateServiceResponse</success_message>
<command>DEACTIVATE^
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spi="http://nsn.com/npm/SoapProvisioningInterface/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<spi:updateService>
<spi:request>
<spi:service>
<spi:serviceIdentifier>
<spi:serviceCode>CFS_Residential_v1</spi:serviceCode>
</spi:serviceIdentifier>
<spi:attributes>
<spi:attribute spi:name="CallingSystem" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">OCS</spi:value>
</spi:attribute>
<spi:attribute spi:name="MSISDN" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">{MSISDN}</spi:value>
</spi:attribute>
<spi:attribute spi:name="HSSUserAdminBlock" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:boolean">true</spi:value>
</spi:attribute>
<spi:attribute spi:name="IMSPrivateID" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">{username}</spi:value>
</spi:attribute>
</spi:attributes>
</spi:service>
</spi:request>
</spi:updateService>
</soapenv:Body>
</soapenv:Envelope>
</command>
<success_message>//ns1:updateServiceResponse</success_message>
<command>ACTIVATE^
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spi="http://nsn.com/npm/SoapProvisioningInterface/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<spi:updateService>
<spi:request>
<spi:service>
<spi:serviceIdentifier>
<spi:serviceCode>CFS_Residential_v1</spi:serviceCode>
</spi:serviceIdentifier>
<spi:attributes>
<spi:attribute spi:name="CallingSystem" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">OCS</spi:value>
</spi:attribute>
<spi:attribute spi:name="MSISDN" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">{MSISDN}</spi:value>
</spi:attribute>
<spi:attribute spi:name="HSSUserAdminBlock" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:boolean">false</spi:value>
</spi:attribute>
<spi:attribute spi:name="IMSPrivateID" xsi:type="spi:singlevalue">
<spi:value xsi:type="xsd:string">{username}</spi:value>
</spi:attribute>
</spi:attributes>
</spi:service>
</spi:request>
</spi:updateService>
</soapenv:Body>
</soapenv:Envelope>
</command>
<success_message>//ns1:updateServiceResponse</success_message>
</action_script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能只是因为您的 XML 文档太大,以至于尝试将其全部放入一个字符串中会导致大量的链式方法调用,并且您的堆栈内存已满。尝试通过以下方式分配更多堆栈内存:
JVM 参数
(如果从 Eclipse 执行:右键单击项目 -> 运行方式... -> 运行配置 -> 参数选项卡 -> VM 参数 -> -Xss1m)
It might simply be that your XML document is so big that trying to get it all into one String makes alot of chanined method calls and your stack memory gets full. Try allocating more stack memory via:
JVM argument
(if executing from Eclipse: right click on project -> Run As... -> Run configurations -> Arguments tab -> VM Arguments -> -Xss1m)