aspose file tools*
The moose likes Tomcat and the fly likes Session Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Session Question" Watch "Session Question" New topic
Author

Session Question

Alister Pate
Ranch Hand

Joined: Sep 13, 2002
Posts: 34
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

Joined: Jan 07, 2002
Posts: 2205
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.


Rob
SCJP 1.4
Alister Pate
Ranch Hand

Joined: Sep 13, 2002
Posts: 34
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

Joined: Feb 20, 2001
Posts: 3695

fyi: multiple hosts still = one jvm.
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

What are the other ways to use multiple JVMs otehr than clustering? Doesn't virtual hosts share the same JVM?


Ashik Uzzaman
Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Ashik, did you read the last comment I made?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Session Question