>>> The "init" method for a servlet provides a place for you to do things
>>> during the Web Server's startup. Is there a way to know when the Web
>>> Server has completely finished starting up and is forwarding requests
>>> to its servlets?
That is not when init() runs. The init() method runs when
> the servlet is being placed into service.
...
> The servlet container calls the init method exactly once after instantiating the servlet.
> The init method must complete successfully before the servlet can receive any requests.
<http://java.sun.com/javaee/5/docs/api/javax/servlet/Servlet.html#init(javax.serv
let.ServletConfig)>
The web server could have been running for years when init() is called. For
that matter, the init() method for that servlet class might have been called
before any number of times on other instances of the servlet.

Signature
Lew
Rob Whiteside - 08 Feb 2008 17:22 GMT
> >>> The "init" method for a servlet provides a place for you to do things
> >>> during the Web Server's startup. Is there a way to know when the Web
[quoted text clipped - 14 lines]
> --
> Lew
Thanks Lew,
you are quite right, I just tested the servletContextListener, and it
isn't what I was looking for after all.
I suppose I should have read the servlet javadoc more carefully,
because it says pretty plainly, that a servlet will not be put into
service until the init method has completed successfully.
Do you know of a way to verify that init is complete?
Rob Whiteside - 08 Feb 2008 17:29 GMT
> Do you know of a way to verify that init is complete?
Or more specifically, that the servlet has been put into service
Lew - 09 Feb 2008 00:28 GMT
>> Do you know of a way to verify that init is complete?
>
> Or more specifically, that the servlet has been put into service
I don't know what you mean by "verify". There are two ways that I can think
of offhand - program invariant checks and log output.
Presumably you care about init() because you want it to establish some
condition for the rest of the servlet's life. Let's say it's to make sure
that the servlet context-wide variable 'foo' has been set to a sensible value,
say, not null. Then in your service() method or the doPost() / doGet() called
by service(), you start with a check for 'foo != null' before doing any other
work.
Of course, the service() method isn't even called unless init() completed.
This technique simply ensures that it completed correctly.
Another, complementary technique is to issue a log statement at the end of the
init() method. This tells you afterward if init() completed, and usually
when. The invariant-check technique ensures your program will only proceed if
init() had completed correctly in the moment.

Signature
Lew