users@jaxb.java.net

Re: clarification on thread safety as stated in FAQ?

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 17 Jun 2004 16:43:53 -0700

> i was wondering if someone might be able to clarify some thread safety
> issues for me. i've read the faq and searched this list's archive for
> thread safety, but still have a question.

Thanks for taking time before posting the question.

> first, i really never use the JAXBContext itself, but always an
> ObjectFactory, which, from the output of xjc, seems to be a convenience
> wrapper around JAXBContext, and so i'm assuming that the two are
> synonymous with respect to threading. perhaps this should stand as the
> first point on which i'll need to be clarificationized:)

ObjectFactory has JAXBContext-ness plus more (such as create*** methods.)
The JAXBContext part has the same thread-safety characteristics as the
ordinary JAXBContext.

> in any event, the FAQ would seem to suggest that i need to have only one
> instance of a somepackage.ObjectFactory in my application. this isn't
> the most onerous task, but one i'd like to avoid if possible. is it
> really unsafe if i create multiple ObjectFactories at a given point in
> the application.

No. You can safely create multiple ObjectFactories and use them. No
problem at all. If you want to use multiple ObjectFactories, by all
means go ahead and do so.

What the FAQ is trying to say is that if you are really into performance,
you can do better by just using one.

>
> also, the FAQ says that the JAXBContext (ObjectFactory?) is thread safe.
> may i assume then that of.createBlah(), where 'Blah' may be some object
> generated from the schema, or a m/u/v, may be accessed simultaneously by
> different threads?

You can invoke any methods on ObjectFactory/JAXBContext concurrently.

> note that i'm not talking about concurrent access to
> the m/u/v they create, just to their createBlah() methods in general.

I know you know this, but just to keep this in the record for other
people's benefit, what you cannot do is to share
Unmarshaller/Validator/Marshaller objects by multiple threads (but you
can call createUnmarshaller concurrently.)


regards,
--
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net