I'm using the StaxEventItemReader to unmarshal xml. As in my import process there can be many files of the same type(I use a custom partitioner to read 1 file per thread), I'm getting a lot of:
o.s.oxm.jaxb.Jaxb2Marshaller : Creating JAXBContext with classes to be bound
I read on https://stackoverflow.com/a/7400735/384984 that the JAXBContext is thread safe. So it seems like that part could be improved and use only 1 instance for that.
I'm using this reader:
public class MultiResourceXmlImportReader<T> extends MultiResourceItemReader<T> {
public MultiResourceXmlImportReader(FileTypeEnum fileType, Resource... resources) {
super();
setResources(resources);
setDelegate(new XmlImportReader(fileType.getRootElementName(), fileType.getXmlEntityClass()));
}
}
with this ResourceAwareItemReaderItemStream:
public class XmlImportReader<T> extends StaxEventItemReader<T> {
public XmlImportReader(String rootElementName, Class<T> modelClass) {
setFragmentRootElementName(rootElementName);
Jaxb2Marshaller itemMarshaller = new Jaxb2Marshaller();
itemMarshaller.setClassesToBeBound(modelClass);
setUnmarshaller(itemMarshaller);
}
public XmlImportReader(String rootElementName, Class<T> modelClass, Resource resource) {
this(rootElementName, modelClass);
setResource(resource);
}
}
Is there anyway to use just 1 instace of a JAXBContext?