aspose file tools*
The moose likes Servlets and the fly likes Session swapping problem under load Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session swapping problem under load" Watch "Session swapping problem under load" New topic
Author

Session swapping problem under load

kapil Gupta
Ranch Hand

Joined: Dec 17, 2001
Posts: 89
Am developing a web application based on spring web MVC framework that runs in in tomcat server. The entry to the webapp is through a login page and after successful validation user is taken to home page that displays a greeting message like Good Morning Mr XYZ. The user name is set as session attribute from Login Servlet and is retrieved by the home page JSP.
During load testing it was noticed that the user name displayed in greeting message was of some other user. This problem occurred only twice and is not reproducible.
What could be the cause of this issue? Should I put the login code in synchronize block so there are no threading issues?
Thanks,
Kapil
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

Are you sure that you have no instance variables in your servelts or JSPs? Properly coded servlets/JSPs rarely need synchronization.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
kapil Gupta
Ranch Hand

Joined: Dec 17, 2001
Posts: 89
Yes, there are not instance variables in servlets other than the singleton spring beans (service classes) that further validates the user from database.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by kapil Gupta:
Yes, there are not instance variables in servlets other than the singleton spring beans (service classes) that further validates the user from database.



That sounds like it could be a problem.
If you have a singleton object (shared by all requests) with instance variables, then it's to be expected that multiple requests could be sharing the same variables.

Can you post the code to one of these classes?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
kapil Gupta
Ranch Hand

Joined: Dec 17, 2001
Posts: 89
Following is the pseudo code for login

The user name is set as member variable of MyCustomSessionObject class and retrieved in the JSP from session object.
 
jQuery in Action, 2nd edition
 
subject: Session swapping problem under load