• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can we have more than one instance of a servlet at container start up

 
Bis Bang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi gyes.. I have a little doubt...
As the life cycle of servlets says that the container will create one instance per servlet at startup or when the 1st request comes up for the servlet. If other requests come in by that time the container will see if there is any intance of that servlet is existing if its there than a new thread will be processing the second request.. and same for other request also.. Now if my servlet is to be designed to handle 1000 request at a time.. will there be 1000 therads processing the request on behalf of Only single instance of that servlet or we can have different concept to do that..(as far as i know instance pooling is available only for the servlet which implements Single Thread Model)...
Thanx in advance....
Bish
[ March 01, 2004: Message edited by: Bis Bang ]
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, there would be 1000 threads running through a single servlet at the same time, but this is a good thing! Think how quickly your server would run out of memory, if there was a separate servlet for each request.
It's a common misunderstanding, but believe me, you don't need separate instances to make your application go faster. Each thread only needs to read the servlet code, and lots of threads can be reading the same code at the same time.
An anology I have used before is that of a movie theater. You don't expect the movie to take longer just because a few more people come in to see it today.
Does that make sense?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic