You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by James Neville <ja...@babcockbrown.com> on 2004/02/16 13:37:45 UTC

How to know when Tomcat has completed startup?

Hi all,

I'm trying to get a certain method within my startup class to *only* 
execute after Tomcat startup has fully completed.

I understand I can implement a LifecycleListener, but there only seems 
to be before/after start/stop events.
(i'm not sure that Lifecycle.AFTER_START_EVENT refers to 'startup is 
complete', or 'startup event was requested')

In short, as part of my Startup procedure, we pre-generate(if rqd) a 
fornightly clandar of 'events' from some JSPs on the same Tomcat instance.
The problem is mainly that we also use Apache/JK2, so a HTTP 500 error 
is generated (the Apache connection can be made, but Tomcat is not yet 
available), unless we can defer until Tomcat has started.
I could, of course, defer the event for a few minutes, but that doesn't 
strike me as much of a graceful approach.

I'm assuming this is probably pretty simple?
Any pointers would be much appreciated. (not google.com, been all 
morning in there! :) )

James


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


Re: How to know when Tomcat has completed startup?

Posted by Rodrigo Ruiz <rr...@gridsystems.com>.
If I had undestood well, you want to invoke a servlet from within your 
own web-app during initialization, to do some data pre-generation.

What about isolating the logic of your "event management" in a helper 
class? This way you could call its methods from within your 
ServletContextListener without needing to wait for the servlets being 
able to respond. Just add your helper instance to the context as an 
attribute in the ServletContextListener, to be sure you use the same 
instance from within your timer servlet, or make it a singleton :-)

HTH,
Rodrigo Ruiz

James Neville wrote:

> Jose,
>
>> James, do you need the servlets to be already initialized???
>
>
> Yes, and they are all defined in web.xml.
> The timer servlet that processes the calendars is the last to load.
>
>> Another thing to consider is that the connector between Tomcat and 
>> Apache is also set up. Because Tomcat and Apache may be completly set 
>> up, but the connector takes a little longer (at lest in my case) 
>> therefore you may get a HTTP Error.
>>  
>>
> This is what causes me HTTP 500 errors.
> The servlets are in fact all instantiated, but they are just not 
> available on port 80 until JK2 has completed whatever it does on startup.
>
> The best thing I can think of is start the timer in a thread, and 
> defer the thread from processing the action for a nominal duration 
> (1/2 mins?).
> Still seems like a dirty way of doing it though.
>
> Maybe I should talk to the JK2 developers.....
>
> Thanks
>
> James.
>
>
> ---------------------------------------------------------------------
> 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: How to know when Tomcat has completed startup?

Posted by James Neville <ja...@babcockbrown.com>.
Jose,

> James, do you need the servlets to be already initialized???

Yes, and they are all defined in web.xml.
The timer servlet that processes the calendars is the last to load.

>Another thing to consider is that the connector between Tomcat and Apache is also set up. Because Tomcat and Apache may be completly set up, but the connector takes a little longer (at lest in my case) therefore you may get a HTTP Error.
>  
>
This is what causes me HTTP 500 errors.
The servlets are in fact all instantiated, but they are just not 
available on port 80 until JK2 has completed whatever it does on startup.

The best thing I can think of is start the timer in a thread, and defer 
the thread from processing the action for a nominal duration (1/2 mins?).
Still seems like a dirty way of doing it though.

Maybe I should talk to the JK2 developers.....

Thanks

James.


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


Re: How to know when Tomcat has completed startup?

Posted by Jose Alfonso Martinez <tr...@linuxcenter.com.mx>.
On Mon, Feb 16, 2004 at 03:44:53PM +0000, James Neville wrote:
> 
> Cancel that - this is called *before* any of the servlets are initialised :(
> Any better ideas?
> 

James, do you need the servlets to be already initialized???

Because Tomcat can be completly set up, and still none of the servlets being initialied. A servlet initializes the first time it is requested. Therefore, if not invoked, it can pass many hours before it gets initialized.

A posible solution could be to add a <load-on-startup> entry in your web.xml
so that the servlet(s) get automatically initialized...

Another thing to consider is that the connector between Tomcat and Apache is also set up. Because Tomcat and Apache may be completly set up, but the connector takes a little longer (at lest in my case) therefore you may get a HTTP Error.

I hope this helps, let me know how you solved it

Jose

> 
> James Neville wrote:
> 
> >
> >contextInitialized is what I needed :) 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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: How to know when Tomcat has completed startup?

Posted by James Neville <ja...@babcockbrown.com>.
Cancel that - this is called *before* any of the servlets are initialised :(
Any better ideas?


James Neville wrote:

>
> contextInitialized is what I needed :) 




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


Re: How to know when Tomcat has completed startup?

Posted by James Neville <ja...@babcockbrown.com>.
Thanks to all who replied.
Solved here - even with an example ;)

http://www.onjava.com/pub/a/onjava/2001/04/12/listeners.html?page=2

|contextInitialized is what I needed :)

|I'll call my startup method when I know the whole ServletContext has 
been initialised.


Cheers,

James.


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


RE: How to know when Tomcat has completed startup?

Posted by Peter Guyatt <pg...@telesoft-technologies.com>.
What about using a session listener.

Why not call your method in the constructor for the SessionListsner

Pete

-----Original Message-----
From: James Neville [mailto:james.neville@babcockbrown.com]
Sent: 16 February 2004 12:38
To: tomcat-user@jakarta.apache.org
Subject: How to know when Tomcat has completed startup?


Hi all,

I'm trying to get a certain method within my startup class to *only* 
execute after Tomcat startup has fully completed.

I understand I can implement a LifecycleListener, but there only seems 
to be before/after start/stop events.
(i'm not sure that Lifecycle.AFTER_START_EVENT refers to 'startup is 
complete', or 'startup event was requested')

In short, as part of my Startup procedure, we pre-generate(if rqd) a 
fornightly clandar of 'events' from some JSPs on the same Tomcat instance.
The problem is mainly that we also use Apache/JK2, so a HTTP 500 error 
is generated (the Apache connection can be made, but Tomcat is not yet 
available), unless we can defer until Tomcat has started.
I could, of course, defer the event for a few minutes, but that doesn't 
strike me as much of a graceful approach.

I'm assuming this is probably pretty simple?
Any pointers would be much appreciated. (not google.com, been all 
morning in there! :) )

James


---------------------------------------------------------------------
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