It's not hard. Just add the following code to your web.xml (the one inside your
webapp/WEB-INF, since conf/web.xml isn't used at all):

<web-app>
    <servlet>
        <servlet-name>
            InitServlet
        </servlet-name>
        <servlet-class>
            InitServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <...>
</webapp>

and then code something like:

public class InitServlet extends HttpServlet
{
    public void init(ServletConfig config)
    {
        // do your init stuff here
    }
}

This way, the servlet will be executed right after you start Tomcat, and before
any requests start coming.

If you have several servets you'd like started at startup (what an odd phrase :),
the number inside <load-on-startup> wil be the order at which they're
initialized.

Enjoy,

Alex.

Andreas Schlegel wrote:

> Hi Paul,
>
> in your answer toRachel you mention a "load-on-startup servlet". Do you
> have/know an example how to write and implement such a servlet?
>
> Greetings,
> Andreas
>
> Paul FitzPatrick wrote:
>
> > I'm not sure, but I've heard on the list that there is an expensive random
> > number seeding process that occurs on the first access to the server. This
> > could be what you are seeing. To make this less obtrusive, you could create
> > a load-on-startup servlet which makes a request to your server so that this
> > delay is incurred automatically and not by the first human user.
> >
> > Regards,
> > Paul
> >
> > -----Original Message-----
> > From: Rachel Gollub [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, January 30, 2001 11:32 AM
> > To: [EMAIL PROTECTED]
> > Subject: Delay in invoking first servlet
> >
> > I've got tomcat running with apache, and everything's working fine,
> > but when I invoke the first servlet from a browser, I get a 60-80
> > second delay.  Everything after that is fast -- it's just that first
> > servlet that's showing the delay.  It doesn't matter which servlet
> > I use, or whether I <load-on-startup> -- it still happens.  Anyone
> > know what's going on, or how to fix it?
> >
> > Thanks!
> > --
> > Rachel Gollub
> > [EMAIL PROTECTED]
> > http://www.equiltblocks.com/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, email: [EMAIL PROTECTED]
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, email: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to