Announcement Announcement Module
No announcement yet.
Thread Safety question related to jaxb2Mashaller and SpringMVC Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Thread Safety question related to jaxb2Mashaller and SpringMVC


    I am new to developing web apps with java and Spring Framework. I have read about thread safety being an important point that needs to be considered while using java for web application development and have fairly understood the reasons behind it. However, while doing the actual coding, I am unable to figure out which beans will be Singleton and which will not.

    In my case, Jaxb2Marshaller is used for working with xml data in a REST application. A Customer class annotated as @XmlRootElement is as follows -

    public class Customer implements RequestNode {
    	private List<String> validationErrors;
    	private String name;
    	private String email;
    	public String getName() {
    		return name;
    	public void setName(String name) { = name;
    	public String getEmail() {
    		return email;
    	public void setEmail(String email) { = email;
    	public Boolean validate() {
    		this.validationErrors = new ArrayList<String>();
    		if( == null ||"")){
    		if( == null ||"")){
    			return true;
    		return false;
    	public List<String> getValidationErrors() {
    		return this.validationErrors;
    And the controller action is as follows

            @RequestMapping(method=RequestMethod.POST, value="/generate")
    	public String generate(@RequestBody String body, Model model){
    		Source source = new StreamSource(new StringReader(body));
    		Customer c = (Customer) this.jaxb2Mashaller.unmarshal(source);
    		//TODO generate response and add response obj to model			
    		return "mytemplate";
    Since the Customer class instance is being created by jaxb2Mashaller , its not clear whether an instance variable in the Customer class will lead to thread safety issues.

    So in general my question is, while using Spring, is it possible to tell in which classes instance variables can be used and where they need to be avoided ?

    Last edited by naiquevin; Feb 18th, 2011, 03:44 AM.

  • #2
    Use [ code][/code ] tags when posting code that way it remains readable.

    Your current setup doesn't lead to any problems a customer is simply recreate when you call unmarshal (it gives you a new Customer)...


    • #3
      Thanks for the reply.