users@jaxb.java.net

Re: XmlAdapter lifetime/concurrency/thread-safety

From: Iaroslav Savytskyi <iaroslav.savytskyi_at_oracle.com>
Date: Tue, 3 Dec 2013 10:36:04 +0100

Hi, Taras,

Here is some info: https://jaxb.java.net/guide/Performance_and_thread_safety.html

As you see you should have additional synchronisation.


Best regards,
Iaroslav

On 2 Dec 2013, at 21:13, Taras Tielkes <taras.tielkes_at_gmail.com> wrote:

> 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
>