Question

I want to have some method run, only after my WAR has been deployed to JBoss.

The problem: Currently I am using @PostConstruct to load saved schedules from the DB. The problem is that I am creating instances of the Schedulers from this method, which in turn is starting the Quartz schedulers, which is stopping JBoss from completing the deploy. If there are no schedules to load, my WAR deploys fine, but if there are schedules they are causing the deploy to fail, because JBoss is "waiting" for the schedules to actually complete.

Is there some way to delay the method call until after it is fully deployed? Or alternatively, is it possible to make Async calls on the Server (from the Server code)?

Was it helpful?

Solution

Wouldn't the simple ServletContextListener solve the problem for you? Just implement whatever you need in contextInitialized method.

OTHER TIPS

Java EE specification heavily refrain any thread manipulation outside facility provided by the application server.

You shouldn't in any case use a container manged thread in an infinite loop; the container expect the thread to be returned. Thread creation can still be done without too much collateral damage (if you don't put several apps on the server as the container won't be able to manage the resources between all the applications) but the any container thread must be returned.

In the new Jboss 7 there is some Java EE scheduling facilities (@Scheduling and timer, with possible persistent timer). A quick search show some example how to run Quartz in JBoss 7: How to enable Quartz scheduling in Jboss AS 7.0?

In older JBoss more advanced integration exist (JCA integration is the only standard way to get finer thread management). Use google to find them.

In JBoss 7, there is a management api.

Maybe you can use it to check if the server is started (with a singleton and a TimerService).

Sample code:

ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999);
        ModelNode op = new ModelNode();
        op.get(ClientConstants.OP).set("read-attribute");
        op.get(ClientConstants.NAME).set("server-state");
        ModelNode returnVal = client.execute(op);

        if(StringUtils.equals(returnVal.get("result").toString(), "\"running\"")){
            LOGGER.info("Server running, init start actions");
            timer.cancel();
        }else{
            LOGGER.info("Server not running, wait");
        }  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top