JAXB Marshalling devouring memory

Hi there.
I noticed some disturbing behavior with how JAXB marshals large XML documents. I have around 5000 data objects which, when marshalled, result in an XML document about 9.5 mb in size. Prior to calling marshal(), I had over 47mb available on my Heap. Before this method returned, an OutOfMemoryError had been thrown. I was able to fix this problem by setting my max Heap size to 128mb.
My concern is how this will scale with larger data sets, as I don't want to keep throwing more and more ram at the problem. I haven't run any concrete benchmarks yet, but I was wondering if anyone has run into this problem before and could share some numbers with me.
Thanks in advance!

Immediately prior to calling marshal(), I have approx 47 mb available out of an original 64. So for 5000 catalog items, I'm using a max of 17 mb; that's 3.4 k for each item bound to JAXB. That's not unacceptable. The problem is that in the process of marshalling this data to XML, over 50 mb is being consumed. This XML is sent to a remote Web Service (the spec allows for xml up to 35mb), so the size of the document is not unreasonable.
I did a little benchmarking, and found this behavior to scale fairly linearly, which is a Good Thing (128mb per 9000 items). However, I'm wondering if JAXB allows for more efficient memory management for marshalling larger data sets (i.e. Serializing binding objects to disk until it's time to build them to xml, or releasing objects as soon as they're marshalled).

Similar Messages

  • JAXB Marshalling

    Hi,
    jaxb marshalling for a xml file takes 8 secs in one system but it takes 1/2 min in another system for the same file. I want to know how to identifyu if there is any difference in the parsers being useed. I searched the Manifest files but unable to find reference to the parser being used. I even compared the version numbers of the API in the Manifest file and all the jars seem to be same version.
    Please help me in identifying what could be the problem.
    Thanks,
    Ravinder

    I don't know anything about either of the computers involved or the XML document involved, but I will take a guess and say there are differences in network access between the two computers.

  • JAXB Marshalling of "double" problem - exponent is in the way

    An element declared as "xsd:double" in the schema is marshalled by JAXB as "3.000404E-4" to represent 0.0003000404 . When I try to process this XML document using XSLT, the standard number() function returns "NaN" because of the exponent in the representation of the number.
    Is there any way to have JAXB marshall this number in a way that is acceptable to XSLT?
    Thanks,
    -Allan

    This seems to have a solution by using JAXB custom bindings. See http://forum.java.sun.com/thread.jsp?forum=34&thread=507037
    Thanks anyway.
    -Allan

  • JAXB marshal "lt;" and "gt;" instead " " and " "... URGENT

    Hi!
    I defined in jaxb that some tag (un)marshal (from/to) org.w3c.dom.Document.
    But when jaxb marshalling, the assigned document has got
    "lt" instead "<"
    "gt" instead ">".
    This is "equals" characthers when is represent in browser, but itegrity of xml file in not same.
    How can I forced "<" and ">"?
    Please, can me anybody help?

    I assume you mean it displays the following substitutions in the output document.
    & lt;      <      less than
    & gt;      >      greater than
    & amp;      &      ampersand
    & apos;      '      apostrophe
    & quot;      "      quotation mark
    { I have had to add an artificial space after the & in the entity reference, to prevent this forum from doing the entity reference subsititution even!}
    These are predefined entity references, which are required for valid xml. Since xml element are delimited by '<' and '>', the parser needs to know that you are not trying to define new elements when you use these characters in element text.
    If you use a parser on the output xml, you will get '<' and '>' back as the resulting element text.
    Scott
    http://www.swiftradius.com

  • JWSDP1.2 JAXB Out of memory exception

    Hai,
    I am using JAXB in JWSDP1.2,while compiling with xjc it is giving out of memory error.I increased the size JVM memory to 1024m.
    It is giving when weinclude some imporrted schemas in the schema.is anyone have idea of this kind of problem. Is there any limit of innerclasees or included schemas.
    Thank you
    Sreen

    HI,
    THanks for the reply..AM using workshop IDE and have tried the "clean" option also but of no use..Is there any other alternative to get rid of this exception ???
    Regards

  • JAXB marshaling and unmarshaling

    I used JAXB to generate nine classes (one is simply a type-safe enum) to correspond to my XML DTD. I then wrote the code to instantiate the root and some child elements which are all added to the root content. Then I am able to call validate() and marshal() on the root element and produce the desired XML. Great!
    The trouble is that I'm having difficulty using these classes to unmarshal the XML that they validated and wrote. Has anyone else seen this? In some cases, the call to unmarshal() returns the root element with no content (e.g., "<myRoot/>"). In other cases, I get an InvalidContentException on a nested element that repeats (e.g., "Expected an end tag for a "fooList" element, but found a start tag for a "foo" element").
    Has anyone else seen this? I've been through the bug parade and didn't catch this mentioned there.
    Thanks!
    Mark

    Here's the code for the problem I'm running into. Is anyone able to reproduce the problem and diagnose it? I must be doing something wrong because the Checkbook example works just fine for me. Please help!
    The obvious trouble here is that Test4.java does not correctly unmarshal the XML that it writes to temp.xml. Where have I gone wrong?
    Thanks,
    Mark
    -------- begin cut (xyz.dtd) --------
    <!ELEMENT Id ( #PCDATA ) >
    <!ELEMENT Name ( #PCDATA ) >
    <!ELEMENT Amt ( #PCDATA ) >
    <!ELEMENT Transaction ( Id, Name, Amt ) >
    <!ELEMENT Transactions ( Transaction+ ) >
    <!ATTLIST Transactions count NMTOKEN #IMPLIED >
    --------- end cut (xyz.dtd) ---------
    -------- begin cut (xyz.xjs) --------
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <xml-java-binding-schema version="1.0-ea">
    <options package="xyz"/>
    <element name="Transactions" type="class" root="true">
    <attribute name="count" convert="int"/>
    <content>
    <element-ref name="Transaction"/>
    </content>
    </element>
    <element name="Name" type="value"/>
    <element name="Amt" type="value" convert="int"/>
    <element name="Id" type="value" convert="int"/>
    <element name="Transaction" type="class">
    <content>
    <element-ref name="Id"/>
    <element-ref name="Name"/>
    <element-ref name="Amt"/>
    </content>
    </element>
    </xml-java-binding-schema>
    --------- end cut (xyz.xjs) ---------
    -------- begin cut (Test4.java) --------
    import xyz.*;
    import javax.xml.bind.*;
    import javax.xml.marshal.*;
    import java.io.*;
    import java.util.Date;
    import java.util.Random;
    public class Test4 {
    private static Random rand = new Random();
    public static void main(String[] args) {
    // need file to work with...
    try {
    File f = new File( "temp.xml" );
    FileOutputStream fout =
    new FileOutputStream( f );
    // make some transactions
    int TransCt = 1;
    Transactions txns = new Transactions();
    java.util.List transactions = txns.getTransaction();
    for (int i=0; i < TransCt; i++) {
    Transaction t = makeBogus();
    transactions.add( t );
    txns.setCount( TransCt );
    txns.validate();
    txns.marshal( fout );
    fout.flush();
    fout.close();
    FileInputStream fin = new FileInputStream( f );
    Transactions t = new Transactions();
    t.unmarshal( fin );
    t.validate();
    t.marshal( System.out );
    catch (Exception e) {
    e.printStackTrace();
    private static Transaction makeBogus() {
    String[] names =
    { "Bob", "Larry", "Tom", "Ted", "Bill",
    "Gail", "Louise", "Sam", "Erin", "Wilma" };
    Transaction transaction = new Transaction();
    // calculate transaction id...
    int range = Integer.MAX_VALUE / 3 * 2;
    int Id = rand.nextInt(range);
    transaction.setId( Id );
    // pick a name
    transaction.setName( names[rand.nextInt(10)] );
    transaction.setAmt( rand.nextInt( 100 ) );
    return transaction;
    --------- end cut (Test4.java) ---------

  • JAXB Marshalling without UnMarshalling

    Hi,
    Using JAXB can I Marshall an java object to xml directly without Unmarshalling it first?
    Thanks.

    well... yes, as long as the java object is in java binding format...

  • JAXB Marshalling Question

    below is what I get for marshalling some JAXB generated class instance, and i notice that several namespace was create ns1, ns2, ns3.... which are actually all sharing the same namespace, is there anyway (any option) that I can set to optimize it, so they can all simply use ns1, and won't define ns2, ns3...
    thank you.
    Jacob
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <aaa xmlns="http://schema.abc.com/def/gh">
    <ns1:HeaderReq xmlns:ns1="http://schema.abc.com/def">
    <ns1:Header>
    <ns1:sessionToken>sessionToken</ns1:sessionToken>
    <ns1:language>eng</ns1:language>
    <ns1:version>version2</ns1:version>
    </ns1:Header>
    <ns1:ddd>web</ns1:ddd>
    <ns1:eee>a</ns1:eee>
    </ns1:HeaderReq>
    <ns2:ccc xmlns:ns2="http://schema.abc.com/def">accountToken</ns2:ccc>
    <bbb>
    <ns3:firstName xmlns:ns3="http://schema.abc.com/def">Jacob</ns3:firstName>
    <ns4:lastName xmlns:ns4="http://schema.abc.com/def">Tseng</ns4:lastName>
    <relationship>SON</relationship>
    </bbb>
    </aaa>

    Hi Jacob,
    Here is the solution I used for getting rid of ns1,ns2 etc..when I was getting ns1,ns2.. etc.along with http://www.xyz.com/xml/yourxml in the generated XML output
    It worked for me. Let me know if you need any further help.
    -bhanu
    Please include the Following Code when you are marshalling the Document
    ======================== Your Main Java File ======================
    try {
              m.setProperty("com.sun.xml.bind.namespacePrefixMapper",new NamespacePrefixMapperImpl());
    // m is the Marshaller Object
    // NamespacePrefixMapperImpl()
    // You have to implement, sample code is given below
         catch ( PropertyException pe)
              System.out.println("Property Exception : " + pe.toString());
    ===============================================================
    Here is the Sample Code to implement NamespacePrefixMapperImpl()
    =========================================================
    import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
    class NamespacePrefixMapperImpl extends NamespacePrefixMapper {
    public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
    // W3c to show a prefix "xsi"
    if( "http://www.w3.org/2001/XMLSchema-instance".equals(namespaceUri) )
    return "xsi";
    // Your namespace http://www.xyz.com/yourxml/ to show prefix "tns"
    if( "http://www.xyz.com/yourxml/".equals(namespaceUri) )
    return "tns";
    return suggestion;

  • JAXB - Marshalling populated Java object into XML

    I have a populated Java object that I'd like to marshall to an xml file.
    I don't instantiate this object from a DTD, nor do I need to generate the object via unmarshalling an xml. I'm just trying to build something akin to a toXML() method for this object.
    Is JAXB what I should be using?
    Any suggestions?
    Thanks a lot.
    Paul

    Hi Paul,
    Did you ever sort this out?
    I too am now having problems with Marshalling to and from XML.
    I have been able to write my own Marshalling class but can't seem to be able to DeMarshal a XML stream to a SOAP object.
    Please reply to this message if you are able to maybe shed some light on my problem.
    I have a populated Java object that I'd like to
    marshall to an xml file.
    I don't instantiate this object from a DTD, nor do I
    need to generate the object via unmarshalling an xml.
    I'm just trying to build something akin to a toXML()
    method for this object.
    Is JAXB what I should be using?
    Any suggestions?
    Thanks a lot.
    Paul

  • JAXB-marshalling problem

    I am trying to use JAXB for binding. The schema compiler works ok i.e i have got the classes generated but when now when i try to apply marshalling i get an error
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/MarshallableObject
    could anyone help what could be the problem with this.
    Any help is appreciated.
    satya

    i am also getting the same error
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/MarshallableRootElement
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at NodeLister.main(NodeLister.java:46)
    i do not know what to do now...i am stuck

  • ITunes devours memory?

    I've been having a lot of problems with iTunes since the initial download, lol. Right here's a pretty good idea of my previous problems if it can help understand my new problem in any way:
    http://discussions.apple.com/thread.jspa?threadID=1634474&tstart=0
    Anyways, on my old computer (which is much worse than my new one), iTunes ran pretty smooth. I'm pretty sure it never passed 50k usage. On this computer, which is very good, it lingers around 300k+ usage, and the CPU usage bonces all over the place, with occasional freezes.
    The CPU usage & freezes happen when i switch from the anywhere to the library (like if im in the music store, and click to go to the library). It pretty much freezes everytime i do. :/
    My computer's pretty good in my opinion, so this isn't horribly important, but sometimes i run high-memory usage programs (like f@h or video conversions), and i'd like to listen to music while they're running.
    Thanks guys

    Bump.
    Sorry for being such a hassle :/

  • JAXB marshal and unmarshal

    hello,
    i have written some code to retrieve data from an XML file and mapped the data and display the mapped data in a new XML file, but i am able to display the mapped data in an MSdos window by running ANT, after this i am unable to write the displayed data in to XML file.
    Input XML file holds --- Firstname(Hello) and
    Lastname(World)
    my MSdos display data ----------- Hello World
    is in this way
    I want the above out put in to XML file
    if any body know this help me.
    Thank you.

    IMHO these classes are not meant to be serialised, the XML produced is the medium that is tranmitted between programs. The XMLB classes are available at both ends to do the marshalling/unmarshalling.I dissagree, xml is just an interface to the outside world, so to speak. I'm working with a project that uses jini and rmi, I really don't need the extra hasle of writting custom serialization classes.

  • JAXB marshalling error..

    Hi, below codes is working properly with normal java app. ( public static void main(String[] args) { ... } )
    try {
        FileOutputStream fout = new FileOutputStream(new File("C:/workspace/mysearch/data/", name));
        JAXBContext ctx = JAXBContext.newInstance(Project.class);
        Marshaller marshaller = ctx.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(project, fout);
    } catch (JAXBException ex) {
          ErrorManager.getDefault().notify(ex);
    } catch (Exception ex) {
          ErrorManager.getDefault().notify(ex);
    }but, it is not working with the Netbeans WizardAction's performAction() method. below is error messages.
    javax.xml.bind.JAXBException:
    at javax.xml.bind.ContextFinder.handleClassCastException(ContextFinder.java:96)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:205)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
    at dstinfo.mysearch.wizard.ProjectWizardAction.actionPerformed(ProjectWizardAction.java:56)
    at org.openide.awt.AlwaysEnabledAction.actionPerformed(AlwaysEnabledAction.java:89)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
    at java.awt.Component.processMouseEvent(Component.java:6216)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
    at java.awt.Component.processEvent(Component.java:5981)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4583)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4413)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2475)
    at java.awt.Component.dispatchEvent(Component.java:4413)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

    Heya,
    I have no supportting evidence for this, but I'd assume if you annotate the property in the way shown in your example, the framework would then try to generate the appropriate getter() method to be used when marshalling the data. I'd guess you could annotate the property with the @XmlTransient annotation and use the default getter() method and avoid this error, no ?
    Good luck,

  • JAXB: Marshalling complex nested data structures?

    Hello!
    I am dealing with complex data structures:
    Map< A, Set< B > >
    Set< Map< A, B > >
    Map< A, Map< B, Set< C > > >
    Map< A, Set< Map< B, C > > >
    [and so on](NOTE: In my case it doesn't matters if I use Set<?> or List<?>)
    I wanted to write wrappers for JAXB for these data structures, but I have no idea how.
    My idea was: write XmlAdapter with generics for Map, Set and List, but it failed:
    "[javax.xml.bind.JAXBException: class java.util.LinkedList nor any of its super class is known to this context.]"
    because I was using LinkedList<T> inside the XmlAdapter (it seems that from the point of view of JAXB,
    LinkedList<T> is same as LinkedList<Object>)
    Any ideas?

    According to sec 4.4 "By default if xml schema component for which java content interface is to be generated is scoped within a complex type then the java content interface should appear nested within the content interface representing the complex type. ".
    So I doubt that worked with beta and you may have to represent this anonymous complex type as a named complex type to avoid the nesting.
    Regards,
    Bhakti

  • JAXB marshalling complexType elements

    Does anyone know why JAXB always marshalls complexType elements with a seperate start and end tag, even if the element has no content?
    i.e.
    Given the schema element declaration:
    <xs:element name="foo" type="fooType"/>
    <xs:complexType name="fooType">
    <xs:attribute name="value" type="xs:string" use="required"/>
    </xs:complexType>
    Why do I get:
    <foo value="bar"></foo>
    Instead of:
    <foo value="bar"/>
    Is their a setting / property to control this behaviour?
    If not then I certainly think there should be because this will bloat the 5Mb XML files I am currently dealing with by quite a lot.
    Cheers,
    Simon

    I have exactly the same trouble here. Did you find a solution? If so, please contact me. I am so afraid of increase the amount space used to store all XML files.
    Thanks in advance
    Julio Garc�a
    [email protected]

Maybe you are looking for