I think you will have to tell us a bit more about what you want to know.
The servlet API is by its nature concurrent. The service(..) and doXX(..) methods of a servlet (and thus any methods they call) can and will be executed by many threads at once, under the control of the servlet container.
Are you asking how to ensure that any servlet code you write is "thread safe" (also known as "reentrant") ?
I think, you must localize all your objects and instances that will solve the concurrency problem. For instance, define a separate class, containing all the objects you are using inside the servlet. Now instantiate it inside the servlet and access them through this instance. This should solve your concurrency problem, that normally we face.
What is the advantage of using an inner class defined in a servlet over instantiating some class defined in a separate file and "adding it" by using the setAttribute() method of ServletContext, ServletRequest or HttpSession objects?
I first time read a solution like that Dilip. Is this widely used in the industry? I doubt this.
Creating a class to hold user specific data is done all the time. For one thing, it makes things simpler than plugging various bits into the session and hauling them back out again. Note that we are NOT talking about putting everything you use in this class, just the user specific data. If you are using JSP, this class is an obvious candidate for the JavaBean interface.
Another (frequently un-appreciated) reason to create such a user-specific class is the ease of debugging. You can test it outside the servlet environment - a vast simplification.
Bill (Avoid the SingleThreadModel like the plague - if you think you need it, your architecture is wrong.) [ July 12, 2004: Message edited by: William Brogden ]