Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is it guaranteed that web server will initialize all web application on the server startup time  RSS feed

 
chatchai chailuecha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am implementing a module that need to be executed at the start up time of servlet container.
The module is for product license checking. The module must be run when administrator execute startup script to start web application server.If license is expired then there will be error in server log file so the admin knows immediately that the startup is failed.

I knows that ServletContextListener is normally used to do this kind of thing but when I took a look at servlet specification , I've become skeptical.

public void contextInitialized(ServletContextEvent sce)
Notification that the web application initialization process is starting. All
ServletContextListeners are notified of context initialization before any filter
or servlet in the web application is initialized.


It seems like the spec doesn't say anything about servlet container startup. ServletContextListener can be applied in my use case only if servlet container always initialize all deployed web applications as part of its startup mechanism which the spec doesn't seem to guarantee that.

I have found some references suggesting that ServletContextListener is will be called on server startup
void contextInitialized(ServletContextEvent e) :
Called when a Web application is first ready to process requests (i.e. on Web server startup and when a context is added or reloaded)


Could you help me find out whether it is guaranteed that web server will always initialize all deployed web applications on the server startup time?

Thanks very much
Chatchai Chailuecha




 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65897
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Specification guarantees that the listener wil execute before any servlets are loaded and any requests are served. Why isn't that good enough?

That said, I've never seen a container not execute the listener immediately upon startup. But the spec allows for waiting until it actualy has to do something.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65897
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, if that's not "good enough", you really don't have any alternatives.
 
chatchai chailuecha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:The Specification guarantees that the listener wil execute before any servlets are loaded and any requests are served. Why isn't that good enough?

That said, I've never seen a container not execute the listener immediately upon startup. But the spec allows for waiting until it actualy has to do something.


Hi Bear,

Thanks for your reply.
The reason I need the use case is that I want the administrator to immediately notice that there is exception in license checking e.g. The license may become expired. I don't what the admin to start web server and wait for the first request from client just to find out that the license is expired.

I can specify in product admin guide that, after server is started, admin must make an initial request to the web application to check if it is functional or not but I prefer something more programatically.
 
Ravinderjit Singh
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can add <load-on-startup> tag to you web.xml.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65897
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravinderjit Singh wrote:You can add <load-on-startup> tag to you web.xml.

That has nothing to do with the subject at hand. The load-on-startup element is used to control how servlets are loaded and has nothing to do with startup listeners.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!