• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Weird session behavior

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
So there I was, trapped in the jungle. And at the last minute, I was saved by this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic