This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Hi, If I have a webiste that uses a servlet, and this servlet records username and password of a user that logs into my site. Does each client that access my servlet gets his own instance of the servlet? If not, should I use threads to ensure that each client will get his own share of servlet's resources? thanks, Alex
All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
The Servlet APIs are designed to take care of this problem. Normally only one instance is created, however, each request is handled in its own Thread, with its own request and response objects. Assigning threads is handled by the servlet engine, you don't have to worry about it. You only have to worry about synchronization when more than one request may access an object at the same time. Any good servlet book will explain this in detail. Bill
No, you don't have to make a new thread. As the previous poster explained, each HTTP Request that comes into the servlet is already on its own thread. Basically, the servlet framework is handling spawning all of the threads for you. I second the advice to go read a good servlet book. In particular, pay attention to the part on threading, and also the part about HttpSession (which is the way to avoid having to do any synchronization). Kyle Brown ------------------ Kyle Brown, Author of Enterprise Java (tm) Programming with IBM Websphere See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information. [This message has been edited by Kyle Brown (edited October 04, 2001).]