users@jaxb.java.net

Re: Is Marshall thread safe?

From: Adam Zell <zellster_at_gmail.com>
Date: Wed, 26 Aug 2009 11:34:53 -0700

The following URLs may be useful:

https://jaxb.dev.java.net/faq/index.html#threadSafety
https://jaxb.dev.java.net/guide/Performance_and_thread_safety.html

In my application, I maintain separate pools for marshaller and unmarshaller
objects. It is advisable to reset the objects to their default properties
(e.g. setXXX) before returning them to the pool.

On Wed, Aug 26, 2009 at 7:06 AM, jyoti chhabra <jyoti.chhabra_at_gmail.com>wrote:

> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>


-- 
Adam
zellster_at_gmail.com