views:

45

answers:

2

We have a Java app that runs on Websphere. I have one class that I want to load and initialize as soon as Websphere loads, or as soon as the app is reloaded within Websphere, without waiting for the first web page to be loaded. I'm pretty sure loading it in our subclass of HttpServlet is probably the wrong place. So what is the right place?

+3  A: 

I think you want a ServletContextListener.

Before that was available, people would actually put this kind of code into a Servlet (not necessarily mapped to any url), and have that loaded on initialization. But ServletContextListener is the proper way now.

Goes into web.xml like this:

<web-app>
<listener>
    <listener-class>
     mypackage.MyContextListener
    </listener-class>
  </listener>
<servlet/>
<servlet-mapping/>
</web-app>
Thilo
+1  A: 

Hi,

As Thilo mentioned ServletContextListeners are good for Web Applications.

If your application does not use the Web Components then you could possibly be looking at WebSphere specific extensions too - StartUp Beans.

http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/asyncbns/tasks/tasb_confstb.html

HTH Manglu

Manglu
Thank you for that extra information. It's not what I need, but it's good to have it here in case somebody finds my question in a search.
Paul Tomblin