JAXB performance in Java 8

When unpacking the xml, I see a significant performance degradation from Java 7 to Java 8. I am using 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 400ms to create a JAXBContext and 400ms for unmarshall. When running the same code from Eclipse, it only takes 160ms to create the JAXBContext and only a few milliseconds to unmount.

When switching to Woodstox, the time until the token is canceled drops to a few milliseconds, but it takes about 400ms 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 different? Is there a way to improve it?

+3


source to share





All Articles