You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kishore Subramanian <ki...@agilesoft.com> on 2001/02/14 19:51:16 UTC

Question on ActionServlet design

Hi,

What are the reasons to have only one instance of the ActionServlet (controller servlet) ? 

Can I subclass from ActionServlet and have one servlet for each module in my web application ? What are the implications ?

Thanks,

Kishore Subramanian
Agile Software
Off : 408 999 7128
http://www.agilesoft.com


Re: Question on ActionServlet design

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Kishore Subramanian wrote:

> Hi,
>
> What are the reasons to have only one instance of the ActionServlet (controller servlet) ?
>

To clarify slightly, there is one instance of the controller servlet per web application.

The reasoning is that some resources are truly application wide, and there is zero benefit in duplicating them.  For example,
because servlets run in a multithreaded environment, having more instances of them would not make it run any faster.

Also, a single controller servlet gives you a central point of control where you can guarantee that functions you want
performed happen on every single request.

>
> Can I subclass from ActionServlet and have one servlet for each module in my web application ?

You could if you want, but you're going to run into problems unless you run each module in an independent web app.  If you do
that, there is no particular need to subclass ActionServlet either, unless you need some specialized functionality that is not
already provided.

If you run your modules in separate webapps, then each webapp is pretty much autonomous -- servlet context attributes,
sessions, and even static variables in Java classes do not cross the boundary between webapps.

> What are the implications ?
>

Trying to run mutliple instances of ActionServlet in the same web application (whether subclassed or not) would cause the
servlet context attributes set up by the ActionServlet instances that started first to be wiped out by the attributes created
in the ActionServlet instance that started last.  This would be a Bad Thing (tm) :-)

>
> Thanks,
>
> Kishore Subramanian
> Agile Software
> Off : 408 999 7128
> http://www.agilesoft.com

Craig McClanahan