Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet Container  RSS feed

 
Vimal Bharathi Andiappan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When we call a new servlet it will create an instance and service to the user. Then another user can call the same servlet it wont create the new instance, but give the service from already created instance. My question was how it works and how it does the service.
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case the previously instantiated instance of the servlet class is used. container calls the service method in new request thread. service method processes the request and generate the response.
 
Gopikrishna Kunisetty
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Process goes like this:
1. When user initiates a request, the servlet container tries to map the request with servlet that are declared in the Deployment descriptor.
2. Once the container identifies the required servlet, it will create an instance of that servlet.
3. Once the instance is ready, the container allocates a thread for the request and calls the service() method of the servlet, passing the request and response objects as arguements..
4. The service() methods takes care of invocation of http method. (i.e, GET, POST etc..)
5. After completing the service the container removes the thread or moves it to the container-manged thread pool.

Here you have to observe that, each request will run in separate thread and only one instance of servlet will be created per JVM.
 
Gaurav Agarwal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Krishna stated only one instance is created and all the upcoming request is handled by different thread which is done by calling run() method and it is a servlet container responsibility to manage the thread for each request.

Hope this clerify your concept
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!