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

one instance per servlet or pooled instances  RSS feed

 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I seem to get conflicting theory on how many servlet instances per servlet the container creates.

One says that the container creates exactly one instance and having multiple threads to handle requests. The other says that container may create a pool of servlet instances to use. Assuming a single JVM.

The pooled instance seems to make sense. But who is right?
Thanks.
Yan
 
Sharad Agarwal
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yan,

In general the container will create one instance of your servlet. This servlet then spawns a thread for each request. You can, however, define your servlet to implement the SingleThreadModel interface which forces the servlet to be single-threaded. In that case, the container will create a new instance of the servlet for each request. For performance reasons, the container may choose to create a pool/etc.

Hope this helps.
[ June 23, 2005: Message edited by: Sharad Agarwal ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is NO (zero)(nada) performance advantage to multiple servlet instances in one servlet container. The SingleThreadModel is inherited from very early days of the servlet API when people were just figuring out how to program for the server environment. Like the "invoker" servlet, this hangover just causes trouble.
If you think your application requires it - take another look at your architecture.
Pools of "helper" classes such as DB connections are another story entirely.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!