I am using JAXB with SAX. I am using Unmarshaller to unmarshall the data. It is mentioned here that we have to use UnmarshallerHandler instead of Unmarshaller when combining JAXB with SAX. And then UnmarshallerHandler is not thread safe.
So should I wrap the unmarshalling code inside a synchronized block like below?
synchronized(this) {
UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();
reader.setContentHandler(unmarshallerHandler);
reader.parse(xml);
Foo foo = (Foo) unmarshallerHandler.getResult();
}
Now what is the advantage of using UnmarshallerHandler over Unmarshaller?
No comments:
Post a Comment