users@jaxb.java.net

Is Marshall thread safe?

From: jyoti chhabra <jyoti.chhabra_at_gmail.com>
Date: Wed, 26 Aug 2009 19:36:20 +0530

Hey,

I am using Jaxb in my application. Currently it's cpu intensive.
This is how i use it :
            JAXBContext jaxbContext = JAXBContext.newInstance(packageName);
            StringWriter xmlStringWriter = new StringWriter();
            Marshaller marshaller = jaxbContext.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
new Boolean(true));
            marshaller.marshal(enqueueObj, xmlStringWriter);

enqueueObj is input to function and if of type JAXBElement<T>

I profile my code and found that creation of jaxbContext is costly
compared to other methods.
What i was wondering is that could i make jaxbContext as a static
variable, assuming there is only 1 kind of packageName.
Is the creation of marshaller thread safe? Is there any limit to how
many marshaller could i create? Would it spawn a new thread for it?
What would be a better way to improve performance. Currently size of
my object is from couple of Kbs to Mb. But i do expect it to grow to
couple of Mbs.

Appreciate any pointers.

Regards,
Jyoti