• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Weird session behavior

 
Marc Larochelle
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

I have web application that uses session and store objects in those sessions and it looks like some of those objects are shared from one session to another ... I'm just saving the objects with session.setAttribute and getting the objects with session.getAttribute. The objects are not static at all... And in another environment, it works just nice so maybe it's a tomcat configuration problem ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about the session data being shared between windows on the same system, or on completely separate systems?

If the latter, that's usually a red flag that you've create thread-safety issues in your code.

Do you have any instance variables in your servlets? JSP declaration blocks in your JSPs?
 
Marc Larochelle
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the same tomcat server, the data saved into the sessions are being shared for all the sessions (or a session.setAttribute just orverride everything).
I'm logging on 2 different computers going to the same tomcat server and the sessions are just returning the same objects, but the sessions have different session ids... And I don't think that it's a thread issue. Nothing is declared as static in the objects that I save in the sesion (except constants of course...)
 
Marc Larochelle
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using tomcat in debug mode, maybe it has something to do with it...
 
Marc Larochelle
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nope, the problem doesn't seems to be the debug mode
 
Marc Larochelle
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The object that I save have instance variables that are objects themselves... And I'm saving the "master" object in the session.. I don't know why but could that be a problem ?
 
Marc Larochelle
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using struts and I save the object in the ActionClass as an instance variable... I think this is the problem...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's been years since I've been burdened by Struts, but if I recall correctly Actions must be written in a thread-safe manner. That means no instance variables.
 
Marc Larochelle
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea... That looks like it was the problem. normally, as I just learned, struts gives you a unique object but it could be used after that. So if I set up the property each time I get into the Action, it should be ok (before I looked if the property was null so I was not resetting it).

Thanks for your help !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic