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?
Joined: Sep 10, 2001
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?
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