I read from a site that containers like tomcat create a pool of objects for servlet. This they state that is an example of multithreading.
Can anyone explain me what has a pool of objects to do with multithreading? If I dont declare any global variable inside a servlet, and as each thread gets its own copy of local variables, why cant a single object handle all request?
Now, as containers do it with servlet, what is done with struts action class object? Is it that a single action object takes care of all requests or a pool is created of objects for the action class? If a pool is created, where do we configure the pool size in a web-app?
In Struts 2, a single instance of the Action handles one request and that instance is not reused to serve other requests. I'm not sure about Struts 1.x...
Struts 1 actions are like servlets; there is only one created per application.
Amol H Lekurwale
Greenhorn
Joined: Aug 06, 2009
Posts: 9
posted
0
David,
Does this mean that if more than one request is arriving at the same time or when the first one is being processed, the other has to wait? Or a new instance is created to serve each next request? Also, wouldn't this approach cause a performance issue?
Amol H Lekurwale wrote:Does this mean that if more than one request is arriving at the same time or when the first one is being processed, the other has to wait?
No, the container calls the appropriate instance method in a new thread.
Or a new instance is created to serve each next request?
No, not in Struts 1. In Struts 2, as previously mentioned, a new instance is created for each request.
Also, wouldn't this approach cause a performance issue?
No: object creation in Java is *very* fast. If you're asking about when no new instance is created, also no; multiple threads can call the same method in a single instance of a class.
Amol H Lekurwale
Greenhorn
Joined: Aug 06, 2009
Posts: 9
posted
0
David,
Thanks for your quick response.
One last query : For Webcontainers like Tomcat, JBoss etc. : If my servlet is *not* implementing SingleThreadModel interface, would that mean only a *single* instance of that servlet is created, always? In case by any means, if we are able to specify the pool size in such a case, then how many instances will be created? Single or as many defined in the configurations.