The creation of a ``++JAXBContext.newInstance++`` is a costly operation, and should only be performed once per context and stored - preferably in a ``++static++`` member - for reuse.
In fact, according to the JAXB 2.2 Specification:
____
To avoid the overhead involved in creating a JAXBContext instance, a JAXB application is encouraged to reuse a JAXBContext instance. An implementation of abstract class JAXBContext is required to be thread-safe, thus, multiple threads in an application can share the same JAXBContext instance.
____
This rule raises an issue when multiple instances are created for the same context path.
== Noncompliant Code Example
----
public void doSomething(List<MyObj> inputs) {
for (String input : inputs) {
Marshaller m = JAXBContext.newInstance(MyObj.class).createMarshaller(); // Noncompliant; context created in loop
// ...
}
}
public List<JAXBContext> getContexts(List<Class> inputs) {