• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Question

 
Alister Pate
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys
This is probably an embarrassingly easy question, but I'm a bit confused. Essentially my question is: Does tomcat execute all its different sessions in the same JVM?
So if I had a Singleton class Foo, would session A and session B both return references to the same object? I'm trying to implement some simple cacheing and so on to save on multiple db hits.
Any thoughts gratefully received!
Alister
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general yes, but if you use multiple hosts (virtual hosts) or if you use clustering, there will be multiple instances of the JVM running, and your singleton will only be unique to each instance. For cases like these, you'll have to use some sort of database repository if you only want one instance of something represented accross multiple hosts/clusters.
 
Alister Pate
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that. It's what I thought was the case, but I'm glad to be reassured!
No, there won't be clustering et al. When the system gets big enough to require that, I'll shift it onto EJBs and make it all someone elses problem!
Alister
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fyi: multiple hosts still = one jvm.
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the other ways to use multiple JVMs otehr than clustering? Doesn't virtual hosts share the same JVM?
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashik, did you read the last comment I made?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic