mardi 5 mai 2015

How to marshall large java objects to xml without heap error?

Currently I am using JAXB marshaller to marshall the lasrge java object and it is working but when i recive the large java object application is throwing the OutOfMemoryError: heap space error.

Can some one let me know how to marshall large java object to xml without heap error.

StringWriter writer = new StringWriter();
JAXBContext.newInstance("packageName").createMarshaller.marshall(myObject,writer);
return writer.toString();

Here is the exact stack error,

Caused by: java.lang.OutOfMemoryError: Java heap space
    at java.lang.StringBuffer.ensureCapacityImpl(StringBuffer.java:338)
    at java.lang.StringBuffer.append(StringBuffer.java:114)
    at java.io.StringWriter.write(StringWriter.java:88)
    at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:122)
    at java.io.BufferedWriter.flush(BufferedWriter.java:246)
    at com.ibm.jtc.jax.xml.bind.v2.runtime.MarshallerImpl.cleanUp(MarshallerImpl.java:339)
    at com.ibm.jtc.jax.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:332)
    at com.ibm.jtc.jax.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:249)
    at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)
    at com.ibm.xml.xlxp2.jaxb.marshal.MarshallerImpl.marshal(MarshallerImpl.java:210)
    at com.mine.app.util.AppUtility.marshalXMLPayload(Unknown Source)

Aucun commentaire:

Enregistrer un commentaire