问题
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>
回答1:
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:
-Xss10m
JVM argument
(if executing from Eclipse: right click on project -> Run As... -> Run configurations -> Arguments tab -> VM Arguments -> -Xss1m)
来源:https://stackoverflow.com/questions/8897721/java-lang-stackoverflowerror-in-dom-parser