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
royjaydAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
This is most probably because jaxbConversionManager is not threadsafe.

Very likely


Any idea how i can make it threadsafe in a spring way.

Not really anything to be done in a "Spring way", you just need to make it thread safe, full stop. And to give you ideas, you will need to provide the FULL code for that class.



PS. if you just want to confirm the above, set the jaxbConversionManager to a "prototype", like this...

<bean id="jaxbConversionManager" class="com.junta.util.JAXBConversionManager" scope="prototype"/>

Open in new window


This will provide a separate bean instance to each MessageListener class and so shouldn't have any threading issues. Note that I wouldn't use this as the final solution, it is just something to verify the situation.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
royjaydAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.