Robert Johansson opened SPR-13609 and commented
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]
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
}
Affects: 4.1.7
Reference URL: http://stackoverflow.com/questions/32883373/concurrentmodificationexception-during-high-load-spring-web-rest
Comment From: spring-projects-issues
Juergen Hoeller commented
This seems to be a concurrency issue within the JAXB provider, actually, looking at where the exception comes from.
Note that the JAXB2 RI, coming from the Metro project at GlassFish, explicitly suggests that a JAXBContext
can be reused and just Marshaller
instances need to be isolated per thread: https://jaxb.java.net/guide/Performance_and_thread_safety.html - since this is exactly what we're doing, I wonder whether the bug isn't rather with the JAXB provider itself.
My guess is that the JAXB2 implementation iterates over some metadata structure from the JAXBContext
there, without taking a defensive copy or using a concurrent collection.
Juergen
Comment From: spring-projects-issues
Robert Johansson commented
Any suggestion how to proceed?
Comment From: spring-projects-issues
Juergen Hoeller commented
I would suggest raising this with the Metro project: http://java.net/jira/browse/JAXB/
Juergen
Comment From: spring-projects-issues
Bulk closing outdated, unresolved issues. Please, reopen if still relevant.
Comment From: sankarasr
Still facing the exact same error in the same situation. Please check if it can be resolved.