-
Jan 23rd, 2011, 09:14 AM
#1
Help Need - is Spring bean thread safe on web
Hello,
I have a basic question, am not sure if this has been raised already.
I have a spring application developed for WEB carrying multiple layers.
Across the layers we have multiple beans and they carry member attributes within them.
So i would like to know is there a chance of data getting corrupted within the beans when multiple threads access the same set of beans at any given point of time, as the spring beans by default are singleton in scope.
As we know over the WEB any web container is by default multi-threaded.
Say for example, i have a Facade Bean injected/ wired with a service bean and the service beans are in turn injected/ wired with Repository beans. I have interfaces in all the layers and the beans are injected/ wired using interfaces.
In order to check this i did remote debugging using tomcat on my eclipse for a simple user login module, where in a simpleformcotroller is used to display the keyed in user name on the browser once the submit button is clicked.
code looks just like this
protected ModelAndView onSubmit(Object command) throws Exception {
User user = (User) command; // break point was placed here
return new ModelAndView("userSuccess","user",user);
}
where in the command object User carries the attributes userName and password. On the success JSP userName is displayed.
To test this, i made 3 different web request with different user names and password. On the debug mode i just caught the execution at the above mentioned green like with a simple debug point. When i switched between the three different servlet execution, i was able to see the data getting changed across the clients.
First client was able to see the data entered by 2nd, third was able to see 1st users data and so on..... the ways the data displayed to the client was completely based upon how the thread where allowed to execute.
Last edited by kamalanathan; Jan 24th, 2011 at 01:13 AM.
-
Jan 24th, 2011, 05:56 AM
#2
I suggest the forum search as this question has been asked and answered numerous times.
In general as long as you don't keep state in the class/instance level there is no problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules