| Author |
Instance Pooling
|
Shrinivas Mujumdar
Ranch Hand
Joined: Aug 27, 2004
Posts: 328
|
|
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
Joined: Feb 10, 2001
Posts: 613
|
|
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.
|
All desirable things in life are either illegal, banned, expensive or married to someone else !!!
|
 |
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
|
|
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
Joined: Aug 27, 2004
Posts: 328
|
|
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
Joined: Aug 13, 2004
Posts: 1076
|
|
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
|
Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
|
 |
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
|
|
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
Joined: Aug 15, 2004
Posts: 2874
|
|
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
Joined: Aug 13, 2004
Posts: 1076
|
|
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
Joined: Mar 22, 2000
Posts: 12267
|
|
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
|
Java Resources at www.wbrogden.com
|
 |
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
|
|
|
i have got this word typically from J2EE Tutorial from sun's site. anyways got it now.
|
 |
Bruce Jin
Ranch Hand
Joined: Sep 20, 2001
Posts: 666
|
|
|
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.
|
BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design
Crazy Bikes created by m-Power
|
 |
 |
|
|
subject: Instance Pooling
|
|
|