In particular, is the method javax.xml.bind.DatatypeConverter.parseBase64Binary(String)
thread-safe?
There is nothing in the documentation that suggests the class is thread-safe. Therefore I recommend you assume it isn't.
I'd recommend Base64
from Apache Commons Codec which states it's thread-safe in the documentation.
My reading of the source code is that that implementation is thread-safe.
The parseBase64Binary
method calls a parseBase64Binary
method on a shared DatatypeConverterImpl
object that is lazily created.
It is easy to see that the lazy creation is thread safe. (The code is in another Answer ...)
An examination of DatatypeConverterImpl
shows that it has no instance variables, so there cannot be thread-safety concerns over access / update to the state of the instance.
The DatatypeConverterImpl.parseBase64Binary
method (in turn) calls the static
_parseBase64Binary
method.
The _parseBase64Binary
method uses its input (which is immutable) and local variables that refer to thread-confined objects. The only exception is the decodeMap
variable which is a private static final
array.
The decodeMap
variable is initialized and safely published during class (static) initialization.
Once initialized, the decodeMap
variable is only ever read. Thus, there can be no synchronization issues or memory model "hazards" related to updates.
Of course, this analysis only applies to the version of the class that I linked to. It is conceivable that the method is not thread-safe in other versions. (But the source code is freely available for multiple versions, so you should be able to check this for the version of JAXP that you are using.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With