You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Andoni <an...@indigo.ie> on 2003/04/23 11:55:03 UTC

Loading classes when tomcat starts first.

Hello,

I have a big application which loads a large number of strings from the
database into tomcat's memory when it first starts up.  This is fine because
access is fairly fast from then on.

The problem arises because the server has to be rebooted every night so the
first person to log in to my application each morning has to wait forever
for the strings to be loaded into tomcat.

At the moment I have two ways of getting around this:

1. a jsp page with <jsp:useBean scope="application" ...  tags in it which is
also the login screen.  I then have my reboot script do a fetch on this page
after rebooting each night.
2. a servlet with <load-on-startup> in it's section in web.xml which also
gets fetched by the startup script causing it to load the values into
memory.

I think both of these will be problematic also if I move to a Tomcat-based
login.

QUESTION:
Is there any way I can get Tomcat to load these beans into memory without
having to do a cludgy fetch in my reboot script.

Thanks in advance.
Andoni.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Loading classes when tomcat starts first.

Posted by Michael Gerdau <mg...@technosis.de>.
>2. a servlet with <load-on-startup> in it's section in web.xml which also
>gets fetched by the startup script causing it to load the values into
>memory.

Why do you "fetch" this application ?

>I think both of these will be problematic also if I move to a Tomcat-based
>login.

What should be problematic about this approach.

AFAICT your type of problem is exactly why there is this feature.
Here I'm using <load-on-startup>-type servlets without any additional
external interaction.

Best,
Michael
--
 Vote against SPAM - see http://www.politik-digital.de/spam/
 Michael Gerdau       email: mgd@technosis.de
 OS/2, Windows/0.
 GPG/PGP-keys available on request or at public keyserver



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Loading classes when tomcat starts first.

Posted by Michael Gerdau <mg...@technosis.de>.
>My problem is basically that the first user of my program each morning must
>wait for Tomcat's memory to be populated.
>
>Though both the solutions I listed work, and both load all the classes they
>still leave my first user each morning sitting there for 5 minutes waiting
>for the login screen to load.
>
>I know it is a little trivial but I need users to like the system.  So what
>I want to do is have Tomcat load the classes after rebooting.  This is why I
>do the fetch.
>
>Any clearer?  I'm really not good at describing things!

Here comes an excerpt from a web.xml I'm using together with
a struts-based application:
  <servlet>
    <servlet-name>config</servlet-name>
    <servlet-class>de.technosis.base.ConfigInit</servlet-class>
    <init-param>
      <param-name>config-init-file</param-name>
      <param-value>WEB-INF/config.properties</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

The mentioned applet definitely is executed directly after
Tomcat is (re)started. No user has to wait on anything.

Best,
Michael
--
 Vote against SPAM - see http://www.politik-digital.de/spam/
 Michael Gerdau       email: mgd@technosis.de
 Cats crawl under gates, software under Windows.
 GPG/PGP-keys available on request or at public keyserver



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Loading classes when tomcat starts first.

Posted by Bill Lunnon <bi...@mirrim.com.au>.
Andoni,
Try this. I use this approach to load "static" data for the application
ONCE, when TOMCAT restarts and I do not have to wait for a user to invoke
the process.

First, package the functionality that accesses the strings from the database
into a bean class. Will call this the class StringBean().
Second, create a servlet (ie something that extends HttpServlet. This
servlet has not other purpose but to create and instance of StringBean() and
add it to the servlet context. In the init() method of the servlet, invoke
the StringBean() class and load all the strings from the database.
Third, most important, in the init() method of the servlet add the
StringBean() class to the servlet context (via
getServletContext.setAttribute()) this way all the servlet / JSPs etc in the
context can access the StringBean() class.

You should ensure that any attempts to access the servlet are handled (ie
redirect to a safe page).

HTH

Bill
-----Original Message-----
From: Andoni [mailto:andoni@indigo.ie]
Sent: Wednesday, 23 April 2003 8:27 PM
To: Tomcat Users List
Subject: Re: Loading classes when tomcat starts first.


My problem is basically that the first user of my program each morning must
wait for Tomcat's memory to be populated.

Though both the solutions I listed work, and both load all the classes they
still leave my first user each morning sitting there for 5 minutes waiting
for the login screen to load.

I know it is a little trivial but I need users to like the system.  So what
I want to do is have Tomcat load the classes after rebooting.  This is why I
do the fetch.

Any clearer?  I'm really not good at describing things!

Andoni.

----- Original Message -----
From: "Andy Eastham" <an...@gliant.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Wednesday, April 23, 2003 11:06 AM
Subject: RE: Loading classes when tomcat starts first.


> Andoni,
>
> Please can you expand on what the problems are with your two suggestions?
>
> They both look like they should work to me - I've used both with Tomcat.
>
> Andy
>
> > -----Original Message-----
> > From: Andoni [mailto:andoni@indigo.ie]
> > Sent: 23 April 2003 10:55
> > To: Tomcat Users List
> > Subject: Loading classes when tomcat starts first.
> >
> >
> > Hello,
> >
> > I have a big application which loads a large number of strings from the
> > database into tomcat's memory when it first starts up.  This is
> > fine because
> > access is fairly fast from then on.
> >
> > The problem arises because the server has to be rebooted every
> > night so the
> > first person to log in to my application each morning has to wait
forever
> > for the strings to be loaded into tomcat.
> >
> > At the moment I have two ways of getting around this:
> >
> > 1. a jsp page with <jsp:useBean scope="application" ...  tags in
> > it which is
> > also the login screen.  I then have my reboot script do a fetch
> > on this page
> > after rebooting each night.
> > 2. a servlet with <load-on-startup> in it's section in web.xml which
also
> > gets fetched by the startup script causing it to load the values into
> > memory.
> >
> > I think both of these will be problematic also if I move to a
Tomcat-based
> > login.
> >
> > QUESTION:
> > Is there any way I can get Tomcat to load these beans into memory
without
> > having to do a cludgy fetch in my reboot script.
> >
> > Thanks in advance.
> > Andoni.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Loading classes when tomcat starts first.

Posted by Andoni <an...@indigo.ie>.
My problem is basically that the first user of my program each morning must
wait for Tomcat's memory to be populated.

Though both the solutions I listed work, and both load all the classes they
still leave my first user each morning sitting there for 5 minutes waiting
for the login screen to load.

I know it is a little trivial but I need users to like the system.  So what
I want to do is have Tomcat load the classes after rebooting.  This is why I
do the fetch.

Any clearer?  I'm really not good at describing things!

Andoni.

----- Original Message -----
From: "Andy Eastham" <an...@gliant.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Wednesday, April 23, 2003 11:06 AM
Subject: RE: Loading classes when tomcat starts first.


> Andoni,
>
> Please can you expand on what the problems are with your two suggestions?
>
> They both look like they should work to me - I've used both with Tomcat.
>
> Andy
>
> > -----Original Message-----
> > From: Andoni [mailto:andoni@indigo.ie]
> > Sent: 23 April 2003 10:55
> > To: Tomcat Users List
> > Subject: Loading classes when tomcat starts first.
> >
> >
> > Hello,
> >
> > I have a big application which loads a large number of strings from the
> > database into tomcat's memory when it first starts up.  This is
> > fine because
> > access is fairly fast from then on.
> >
> > The problem arises because the server has to be rebooted every
> > night so the
> > first person to log in to my application each morning has to wait
forever
> > for the strings to be loaded into tomcat.
> >
> > At the moment I have two ways of getting around this:
> >
> > 1. a jsp page with <jsp:useBean scope="application" ...  tags in
> > it which is
> > also the login screen.  I then have my reboot script do a fetch
> > on this page
> > after rebooting each night.
> > 2. a servlet with <load-on-startup> in it's section in web.xml which
also
> > gets fetched by the startup script causing it to load the values into
> > memory.
> >
> > I think both of these will be problematic also if I move to a
Tomcat-based
> > login.
> >
> > QUESTION:
> > Is there any way I can get Tomcat to load these beans into memory
without
> > having to do a cludgy fetch in my reboot script.
> >
> > Thanks in advance.
> > Andoni.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Loading classes when tomcat starts first.

Posted by Andy Eastham <an...@gliant.com>.
Andoni,

Please can you expand on what the problems are with your two suggestions?

They both look like they should work to me - I've used both with Tomcat.

Andy

> -----Original Message-----
> From: Andoni [mailto:andoni@indigo.ie]
> Sent: 23 April 2003 10:55
> To: Tomcat Users List
> Subject: Loading classes when tomcat starts first.
>
>
> Hello,
>
> I have a big application which loads a large number of strings from the
> database into tomcat's memory when it first starts up.  This is
> fine because
> access is fairly fast from then on.
>
> The problem arises because the server has to be rebooted every
> night so the
> first person to log in to my application each morning has to wait forever
> for the strings to be loaded into tomcat.
>
> At the moment I have two ways of getting around this:
>
> 1. a jsp page with <jsp:useBean scope="application" ...  tags in
> it which is
> also the login screen.  I then have my reboot script do a fetch
> on this page
> after rebooting each night.
> 2. a servlet with <load-on-startup> in it's section in web.xml which also
> gets fetched by the startup script causing it to load the values into
> memory.
>
> I think both of these will be problematic also if I move to a Tomcat-based
> login.
>
> QUESTION:
> Is there any way I can get Tomcat to load these beans into memory without
> having to do a cludgy fetch in my reboot script.
>
> Thanks in advance.
> Andoni.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org