javaspringsaajwebservicetemplate

Multiple WebServiceTemplate and SaajSoapMessageFactory performance


I am trying to improve the start up performance of an existing application. This application is currently making service calls to another 8 applications, therefore there are 8 service beans extending WebServiceGatewaySupport. Each of these service beans has its own instance of SaajSoapMessageFactory.

<bean id="serviceBean" class="com.test.ServiceBeanA" scope="prototype"
      p:marshaller-ref="marshaller"
      p:unmarshaller-ref="marshaller"
      p:defaultUri="${service.endpoint}"
      p:messageSender-ref="messageSender">
    <constructor-arg ref="**messageFactoryD**"/>

</bean>

I was wondering if this is necessary or if I can use only one instance of messageFactory for all my service beans. I'm not sure if I need to worry about blocking on message processing. The reason I'm considering this to start with because there are a few seconds spent on each start up of SaajMessageFactory "Creating SAAJ 1.3 MessageFactory ..".

On a similar note, there are also one instance of Jaxb2Marshaller for each service bean. Can I use only instance of Jaxb2Marshaller for all, and combine the context paths.


Solution

  • SAAJ message factories and JAXB contexts are immutable and thread safe, so there is no reason why you couldn't use the same instances for all service beans. Note that I don't believe that creating the SAAJ message factories takes a significant amount of time. On the other hand, creating JAXB contexts can be heavyweight, depending on the number of classes.