You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by "MALET, CREIGHTON C (SBCSI)" <cm...@sbc.com> on 2004/09/08 00:26:24 UTC

JaxMe and Thread Safety

I would like to understand the limits of using JaxMe in a multi-threaded
(read EJB container) environment.
I have read, in the documentation, and I quote: "Note: Marshallers are
reusable, but not reentrant (thread safe)."
Question is - does this mean that JaxMe is usable in a multi-threaded
environment without synchronization as long as objects are not shared
across threads? Or that objects (such as Contexts and Marshallers) have
to be synchronized? Or that you cannot use JaxMe at all in parallel in
multiple threads? 

To put it another way what precautions do I need to take if I have
multiple threads in the JVM using JaxMe in parallel?

Thanks


------------
Creighton Malet
SBC Services, Inc.
(925)823-1463
cm2159@sbc.com

		RESTRICTED - PROPRIETARY INFORMATION
		The Information contained herein is for use only by
authorized employees of SBC Services, Inc.,
		 and its authorized Affiliates.



---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


Re: JaxMe and Thread Safety

Posted by Jochen Wiedmann <jo...@freenet.de>.
MALET, CREIGHTON C (SBCSI) wrote:
> I would like to understand the limits of using JaxMe in a multi-threaded
> (read EJB container) environment.
> I have read, in the documentation, and I quote: "Note: Marshallers are
> reusable, but not reentrant (thread safe)."
> Question is - does this mean that JaxMe is usable in a multi-threaded
> environment without synchronization as long as objects are not shared
> across threads? Or that objects (such as Contexts and Marshallers) have
> to be synchronized? Or that you cannot use JaxMe at all in parallel in
> multiple threads? 
> 
> To put it another way what precautions do I need to take if I have
> multiple threads in the JVM using JaxMe in parallel?

JaxMe's JAXBContext was carefully designed to be fully thread safe and 
reentrant. The suggested use is to have a factory method, that reads the 
context from a static variable.

JaxMe's marshallers and unmarshallers are not thread safe in the 
following sense: Unlike the context, these are configurable. For 
example, the marshaller has a property causing it to emit an XML 
declaration or not.

However, they *are* thread safe and reentrant, as long as you don't 
change the properties. The suggested use is indeed, to create one 
marshaller, unmarshaller, or validator per possible configuration, store 
it in a factory or static variable and use it. The actual marshalling 
and unmarshalling has been carefully coded to put all required 
information (besides the properties, of course) into 
JMXmlSerializer.Data, or JMHandler.Data, respectively.

Note, though, that this use of marshallers and unmarshallers is 
definitely *not* portable. Thread safety and similar questions are 
definitely not covered by the SPEC. Even worse, IMO it wan't even 
considered well, because otherwise the marshaller and its configuration 
would have been clearly separated. JAXB marshallers and unmarshallers 
are definitely heavyweighted objects.

If that clarifies your question, it would be nice, if you could add an 
entry to the FAQ
(http://wiki.apache.org/ws/JaxMe/FrequentlyAskedQuestions) or supply a
patch to the documentation, that helps others.


Jochen




-- 
http://lilypie.com/baby1/050423/1/5/1/+1

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org