users@jaxb.java.net

XmlAdapter lifetime/concurrency/thread-safety

From: Taras Tielkes <taras.tielkes_at_gmail.com>
Date: Mon, 2 Dec 2013 21:13:43 +0100

Hi,

A common use case for XmlAdapter is customization of the way numbers and
dates are marshalled. Since many of the underlying classes implementing
this in the JDK (NumberFormat, SimpleDateFormat) are not thread-safe, I'm
wondering if it is safe to use them without additional synchronization from
a JAXB XmlAdapter.

If the JAXB runtime is caching and reusing (in a concurrent fashion)
XmlAdapter instances, then obviously additional care is required. On the
other hand, if the lifetime of an XmlAdapter instance is limited to a
single marshall()/unmarshall() operation, then this seems to be perfectly
safe.

Unfortunately, as far as I can see, the JAXB specification does not provide
an explicit contract for the lifetime of XmlAdapter instances. Neither did
I see any remarks regarding the need for thread-safety.
Did I miss something in my reading of the specification, or is this
effectively unspecified?

Thanks,
-tt