Performance of JAXB in Java 8

857 Views Asked by At

When unmarshalling an xml I see a huge drop in performance from Java 7 to Java 8. I use the following piece of code:

StringReader sr = new StringReader(xml);
JAXBContext jc = JAXBContext.newInstance(klass, factory);
Unmarshaller un = jc.createUnmarshaller();
Object o = un.unmarshal(sr);
return ((JAXBElement<T>) o).getValue();

I tried JAXB and MOXy - the result is always the same: it takes aboug 400 ms to create the JAXBContext and about 400 ms to unmarshall. When running the same code from within Eclipse it takes only 160 ms to create the JAXBContext and only a couple of milli seconds to unmarshall.

When switching to Woodstox the time to unmarshall drops to a few milli seconds but it takes about 400 ms to create the XMLInputFactory/XMLStreamReader.

StringReader sr = new StringReader(xml);
XMLInputFactory xmlif = XMLInputFactory2.newInstance();
XMLStreamReader xmlr = xmlif.createXMLStreamReader(sr);
JAXBContext jc = JAXBContext.newInstance(klass, factory);
Unmarshaller un = jc.createUnmarshaller();
Object o = un.unmarshal(xmlr);
return ((JAXBElement<T>) o).getValue();

Why is the performance so different? Is there a way to improve it?

0

There are 0 best solutions below