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

Pooling of Servlet  RSS feed

 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are going to use a Servlet as a controler that handle requests / responces for/from clients.

All JSP pages will have a same Servlet as an action.

Now I want to apply pool mechanism for this Servlet. I need 25 objects of Servlet initialy.

How to do this?
[ November 15, 2005: Message edited by: Chetan Parekh ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you intend to have your servlets implement SingleThreadModel there will only be one instance of your servlet per JVM.
That one instance will handle each request in a separate thread.

If you are planning on using SingleThreadModel (which is probably not a good idea as it is deprecated) you might want to read your container's documentation to see how it handles these servlets.

Tomcat, for instance, already pools single threaded servlets.
You woudn't need to do anything.
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben Souther for your valuable input
 
Pranav Shukla
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben

Can you please elaborate this?


Tomcat, for instance, already pools single threaded servlets.


Unless we are using SingleThreadModel there is only one instance of a servlet per JVM. Then what does this pooling mean?

Thanks,
Pranav
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pranav Shukla:
Hi Ben

Can you please elaborate this?



Unless we are using SingleThreadModel there is only one instance of a servlet per JVM. Then what does this pooling mean?

Thanks,
Pranav


Servlets are multi-threaded. You only need one instance to service all of your requests because each request is handled in a separate thread.

With servlets that implement SingleThreadedModel, on the other hand, a new instance is created for each request. At the end of that request, the instance is destroyed. This creates a lot of overhead and slows down the request/response cycle. To alleviate this problem the makers of many servlet engines decided to pool and recycle a number of instances, much in the same way that database connection pools do with database connections.

Since the SingleThreadedModel has been deprecated, it makes no sense to start using them now.
They are still supported for for the sake of older apps that rely on them and developers should understand how they work if they ever run into them while working on an existing application.
[ November 15, 2005: Message edited by: Ben Souther ]
 
Pranav Shukla
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben.

Got it!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!