esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

How does threading work in Servlets?
Every Servlet contains a doGet or doPost method.
When we deploy a servlet the init method of the servlet is called. And after it has been deployed on each request of the servlet a separate thread is created to process the doGet/doPost method of the servlet.
So all the instance variables of the servlet are not thread safe.
We can override this behaviour by implementing SingleThreadedModel in the servlet which tells the servlet container to create a new Servlet instance for each client's request instead of using a single Servlet Instance.

Whether we should implement single threaded model or not depends solely on our design.


Further Information
Author of answer: Khem Chand Sachdeva

Comments
Comments to this answer are only viewable by members. Login or become a member!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.