Hi,

I usually recommend to program the Application-Scope beans as
"lazy-initializing". In this way only the necessary data is prepared.

Doing it in the init()-method can be usefull. BUT:
In our company we had the case that a web-app could never be started,
because of a init()-method taking too long. A control-mechanism 
(robot user) that should check whether the application was running
decided that the application was dead and restarted the server...

The solution was not to use the init()-method to initialize
application-scope data (the whole method took more than 10 minutes
getting lots of common data using a corba-service).
Reading up on the spec teached us, that during the init()-method of 
a servlet no other request can be handled by the servlet-engines.

If only it would be possible to specify a "non-blocking" secondary
init-phase. But that discussion belongs to the servlet-spec discussions...

just my 2cents
Alexander

-----Original Message-----
From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
Sent: Donnerstag, 15. August 2002 17:36
To: Struts Users Mailing List
Subject: Re: Initialisation




On Thu, 15 Aug 2002, Howard Miller wrote:

> Date: Thu, 15 Aug 2002 14:50:46 +0100
> From: Howard Miller <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
> Subject: Initialisation
>
> Errr... stupid newbie question coming up.
>
> If I want to create objects in the Application Scope the design notes for
> Struts says.... "application scope beans are initialized in the init()
> method of a startup servlet".
>

Well, they *can* be done there, and it's very common.  But this is not the
only choice.  Application scope attributes can be created at any time.

> But, and I'm sure I'm missing something here, I haven't got an init() method
> because the servlet belongs to Struts. So where do I put my innitialisation
> code?
>

In Struts 1.0.x, the common pattern is to subclass ActionServlet and
override the init() method for this kind of thing:

  public class MyActionServlet extends ActionServlet {

    public void init() throws ServletException {

      // Perform standard Struts initialization
      super.init();

      // Perform my extra initializations
      ...

  }

}

In Struts 1.1, you have the additional option of creating a PlugIn
implementation and registering it in your struts-config.xml file.  A
PlugIn has init() and destroy() methods very similar to a servlet, and are
called at startup and shutdown times as you would expect.  You can have as
many PlugIn instances as you need.

The struts-example webapp in 1.1 uses a PlugIn to set up and shut down its
pseudo-database.  Take a look at the included sources to get an idea of
how it all fits together.

> I noticed plugins in earlier posts, but there isn't any documentation that I
> can find - is this what I'm looking for?
>
> Sounds like a fundamental thing to want to do, which is why I'm sure I'm
> missing something really obvious!
>
> Cheers...
>
> Howard
>

Craig


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to