• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Action class object pool?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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?

Regards.
Amol
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts 1 actions are like servlets; there is only one created per application.
 
Amol H Lekurwale
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Regards,
Amol
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know there will only ever be one instance of a servlet created, but I could be wrong.

SingleThreadModel has more to do with the underlying threading than with instantiation.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic