• 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

Servlets and Static variables...

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know that a servlet is multithreaded... However, I am wondering about the staic varibales... I know that if you declare a variable static that it will be one instance of that variable to share across each servlet that is instantiated...

But does it save me anytime processing time...

Let's say that I have an engine object that in my servlet I pull from the session as well as a dbPool (somethe to make db connections). I should make those static, instead of pulling them out of the session each time... But does it save me any time?
 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And just to add to that, I pull everything out from the session and store it in variables inside my init() method... But The variales that are declared as emmber variables of the servlet are not static... They won't change so they need to be static but does it by me anything performace wise?
 
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
Neither of the schemes you mentioned will save any measureable time.
Compared with all the work that goes on in interpreting a request and creating a response, all tricks like this are insignificant and will only make your code harder to understand.
Go for clarity of code - make it work, then if it is too slow, profile to understand why. Premature optimization is the root of all evil.
Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic