When running load tests on a rest service, each request has random xml content, following exception occurs occasionally. It seems as the higher load the more likely that it occurs.
Current implementation in Spring for unmarshal xml to java objects does not seem to be thread safe?
13:23:38,314 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/fault-code-translation].[SpringApplication]] (http-/0.0.0.0:14080-36) JBWEB000236: Servlet.service() for servlet SpringApplication threw exception: java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901) [rt.jar:1.8.0_31] at java.util.ArrayList$Itr.next(ArrayList.java:851) [rt.jar:1.8.0_31] at com.sun.xml.bind.v2.runtime.reflect.Lister$CollectionLister$1.next(Lister.java:288) at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:139) at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:159) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:358) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:593) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:340) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494) at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323) at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251) at org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter.writeToResult(Jaxb2RootElementHttpMessageConverter.java:181) [spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.writeInternal(AbstractXmlHttpMessageConverter.java:66) [spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:208) [spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:161) [spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:101) [spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
Implementation
import org.springframework.web.bind.annotation.*
APPLICATION_XML_V1 = "application/vnd.nnn.nnn.nnn.v1+xml"
@RequestMapping(
value = "/{language}/batchtranslation",
method = RequestMethod.POST,
consumes = {MediaType.APPLICATION_XML_V1})
public Response translateBatchForLanguage_1_0(@PathVariable("language") String language,
@RequestBody String body){
// Implementation code
}
The exception occures before implementation code is executed, it occurres inside spring code.