We help IT Professionals succeed at work.

Spring multithreading issue

royjayd
royjayd asked
on
194 Views
Last Modified: 2015-10-01
Dear experts

I am facing a multi threading issue in our spring environment.

In spring-config.xml we have
<bean id="jaxbConversionManager" class="com.junta.util.JAXBConversionManager"/>

Open in new window



JAXBConversionManager.java has unmarshal method
public class JAXBConversionManager{
	@SuppressWarnings("unchecked")
	public <T> T unmarshal(Document msg) {
		//convert from xml to object and return 
	}
	}

Open in new window

     
      
I have two classes
	public Class1 implements MessageListener{
	@Autowired
	private JAXBConversionManager jaxbConversionManager;
	
	private void method1(Document message)  throws Exception {
		Customer customer = jaxbConversionManager.unmarshal(message);
		LOGGER.info("Customer object1 is", customer.toString());
		moveForward(customer);
		}
	}
	
	public Class2 implements MessageListener{
	@Autowired
	private JAXBConversionManager jaxbConversionManager;
	
	private void method2(Document message) throws Exception {
		Customer customer = jaxbConversionManager.unmarshal(message);
		LOGGER.info("Customer object2 is", customer.toString());
		moveForward(customer);
	}
	}

Open in new window

     
      both above classes are using jaxbConversionManager object.
      
      Document message passed to method1() from Class1 was actually visible in Class2.method2() , i was able to confirm that in the log statement
      LOGGER.info("Customer object2 is", customer.toString()); --> prints message which came to method1
      
      This is most probably because jaxbConversionManager is not threadsafe. Any idea how i can make it threadsafe in a spring way.
      
      
      Thanks
Comment
Watch Question

IT Business Systems Analyst / Software Developer
CERTIFIED EXPERT
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
thanks
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.