Link to home
Start Free TrialLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

Spring multithreading issue

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
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jay Roy

ASKER

thanks