One trick is to move all the code out of your servlet into a threadsafe class:
WorkerClass is not shared by multiple threads the way Servlet is, so it can use member variables. The vendor framework I'm using now does this. There is essentially one servlet that gets the right worker class for the request from a factory.
What's the downside? They must have designed servlets the way they are for some reason. The servlet design - one instance shared by many threads - reduces object creation and destruction. This trick guarantees one object created per request. How much does that matter? Anybody know? Any other pros & cons?
Editing - I just noticed you asked JSP and I answered Servlet. I haven't written enough JSP to know just how much the difference matters ... waddya think? [ July 19, 2004: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
How will I make session variables thread safe in a JSP page? and How can I create a method in a JSP page. Is it possible?
Variables held in a session are isolated from all other user sessions - the only time that they are not completely thread safe is if you are processing multiple requests from the same user at the "same time" -as might occur with a frameset. For creating a method in a JSP, I recommend you read a good tutorial on JSP. Here is a good place to start. I recommend the JSP "Reference Card" - very handy. Bill
Don't use JSPs for anything except displaying information, do all the rest in servlets.
How often does that mantra need to be repeated? Why did Sun ever include the capability for scriptlets in the JSP spec? Why do people keep posting JSP questions in the servlet forum? [ July 20, 2004: Message edited by: Jeroen Wenting ]