• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instance Pooling

 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I have one question about instance pooling
Can a programmer control the number of instances for servlet & JSP by specifying no. in any tag in deployment descriptor?
This is possible in EJBs
thanks in advance
Have a nice time always.
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can a programmer control the number of instances for servlet & JSP by specifying no. in any tag in deployment descriptor?


If you are not implementing single threaded modle then only one instance of Servlet or jsp (converted to servlet) will serve all the requests.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Praful Thakare:


If you are not implementing single threaded modle then only one instance of Servlet or jsp (converted to servlet) will serve all the requests.


just want to add a word in this.

If you are not implementing single threaded modle then typically only one instance of Servlet or jsp (converted to servlet) will serve all the requests.[/QB]
 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, i am not talking about SingleThreadModel. in normal case can we control no. of instances those are created by Server in case of Instance Pooling by specifying some no. in Deployment descriptor?

thanks.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shrinivas Mujumdar:
can we control no. of instances those are created by Server in case of Instance Pooling by specifying some no. in Deployment descriptor?


Well I haven't tried this ...

1. Create a class level variable.
2. Verify against no. of instances /Increment it by one in constructor of class.
3. If variable is exceeding no. of instances to be expected throw an custom exception from your cunsturctor that no more instance can be created.

adeel what is your view
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shrinivas Mujumdar:
Well, i am not talking about SingleThreadModel. in normal case can we control no. of instances those are created by Server in case of Instance Pooling by specifying some no. in Deployment descriptor?

thanks.


Ok, now i am also not talking about SingleThreadModel. typically all the request are entertained by only one instance of the servlet. your question would become more rational if talk about SingleThreadModel. Because there is an instance pool when implementing SingleThreadModel.

I dont think we have any that kind of element in deployment descriptor. it depends on the container implementation how it deals with the requests.

when it needs to maintain an instance pool
when need to add more instances to the pool
when need to discard instances from the pool

How can we decide how many instances should be in the pool, or should not be there??
[ October 19, 2004: Message edited by: adeel ansari ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shailesh Chandra:


Well I haven't tried this ...

1. Create a class level variable.
2. Verify against no. of instances /Increment it by one in constructor of class.
3. If variable is exceeding no. of instances to be expected throw an custom exception from your cunsturctor that no more instance can be created.


Chandra, it could be an approach but ...

its not good to override the servlet class constructor, whatever we like to do at construction time we should do that in init() method. and init() method executed only once.

or may be i haven't got you properly.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed..

it is not good approach !!!

I am just looking possibility if sometime we face such critical requirement.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
typically all the request are entertained by only one instance of the servlet.

It is NOT just TYPICALLY, it is ALWAYS. The servlet API says specifically that if you have a single servlet container (ie Tomcat) running, it will create ONLY ONE instance of a servlet per servlet declaration. Section SRV 2.2 of the servlet 2.4 specification.
Everybody seriously interested in servlets and JSP should have copies of the published APIs. http://java.sun.com/products/servlet/ is a good place to start.
Bill
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have got this word typically from J2EE Tutorial from sun's site. anyways got it now.
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although only 1 instance per servlet, there can be multiple threads of the same servlet running at the same time. Strange error can occur if the servlet is not coded thread safe.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic