• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mutiple thread issue in Tomcat application

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic