aspose file tools*
The moose likes Tomcat and the fly likes Mutiple thread issue in Tomcat application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Mutiple thread issue in Tomcat application" Watch "Mutiple thread issue in Tomcat application" New topic
Author

Mutiple thread issue in Tomcat application

bujin wang
Ranch Hand

Joined: Jun 21, 2003
Posts: 48
Hi,
Recently I am working on a Tomcat application. This application basically a generic java classes which have nothing to do with jsp and servlets. It is the jsp pages and servlets to call these java classes.
Now, as we understand that there might be multiple calls to these classes at the same time from java pages. Do we have thread issue here? Do I need to synchronize the calls to the shared fields? I know there are problems with multiple calls unless Tomcat know how to seperate the seessions.
Even though Tomcat load the classes based on the session, how do I implement singleton across sessions?
Thanks a lot.
Bujin
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
This is really a general servlets/JSp problem so you will see more related discussions in those forums.
You use the terminology
might be multiple calls to these classes at the same time from java pages.

but of course what you are probably talking about is calls to methods in instances of classes.
The key question is - does each request get its own instance of a class to work with? If so, there will be no interference with instance variables. If all requests work with the same instance (or you are using static methods and variables), than yes, there will be interference.
Bill
bujin wang
Ranch Hand

Joined: Jun 21, 2003
Posts: 48
Thanks very much for your reply.
Acutally in this application, most of the time, I don't want to share instances. That is the instance are not shared. However I have implemented a cache which will store resources across all the requests. In this case, I do want all my requests to acess the same cache. Currently my cache is implemmented as singleton, I hope that way all the request will only acess the same cache instance. Please note that my cache aims at performance.

In both the cases listed above, do you see anything abnormal? Any gotchas?
Thanks,
Bujin
bujin wang
Ranch Hand

Joined: Jun 21, 2003
Posts: 48
Thanks very much for your reply.
Acutally in this application, most of the time, I don't want to share instances. That is the instance are not shared. However I have implemented a cache which will store resources across all the requests. In this case, I do want all my requests to acess the same cache. Currently my cache is implemmented as singleton, I hope that way all the request will only acess the same cache instance. Please note that my cache aims at performance.

In both the cases listed above, do you see anything abnormal? Any gotchas?
Thanks,
Bujin
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Any cache would certainly have to be a singleton with synchronized access - unless you are doing the cache simply as an exercise or have objects known to take a lot of resources to create, I suggest you do some measurements of actual object creation time. Simple objects are quite fast.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mutiple thread issue in Tomcat application