Question

I have webproject on Java EE 5 and Websphere 7.0 I need to create scheduler and start it after deploy application. What I tried: I create EJB with interface:

@Local
public interface ISchedulerBean {

    public void executeTimer(Timer timer);
    public void createTimer();
}

stateless session bean implements this interface. Method createTimer creates timer instance from TimerService. This part of code work fine. Also I need to call method createTimer() after application deploy. I tried:

  1. Add listener servletContext:

    public class SchedulerInitialiserContextListener implements ServletContextListener { //service to lookup ejb private WebServiceLocator webServiceLocator; private SchedulerService schedulerService;

    public SchedulerInitialiserContextListener() { webServiceLocator = new WebServiceLocator(); schedulerService = webServiceLocator.getSchedulerService(); }

    public void contextDestroyed(ServletContextEvent ctx) {
    }
    
    public void contextInitialized(ServletContextEvent ctx) {
        schedulerService.createTimer();
    }
    

    }

  2. create Servlet with 1 where inject SchedulerBean in init() method and call createTimer.

But this does not work, because at first webspere deploy web application, call listeners, initialize servlets, and only then deploy ejb.jar in which all ejb are located. I can see that in webshpere log file. So when I try get ejb throw @EJB annotation or lookup I get Exception, beacause ejb has not been found. May be is other approach to start timer after deploy ejb module or change deploy order?

Was it helpful?

Solution

You can set the startup order of your modules.

Assuming you develop with Rational Application Developer do the following:

Right click your ear project and click Java EE -> Open WebSphere Application Server Deployment.

Look for the Application section, you will see all the modules and you can set the Start weight for each one.

Make sure your web project containing the Context Listener has the largest value an you should be fine.

  • This operation creates an ibmconfig directory under your ear project's META-INF, make sure you package it in your build process
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top