mariu
mariu

Reputation: 161

Add logic to Jboss startup/shutdown

How is it possible to run some EJB logic during the server start/stop ? I am using JBoss 5 and EJB 3.0. Thanks.

Upvotes: 2

Views: 1893

Answers (2)

Nayan Wadekar
Nayan Wadekar

Reputation: 11602

MBeans can be used as JBoss provides ServiceMBean interface & ServiceMBeanSupport abstract class to execute custom code during startup/shutdown.

Override life-cycle callback methods to add custom logic.

For further reference, see JBoss Service

Upvotes: 0

Heiko Rupp
Heiko Rupp

Reputation: 30934

Server start is relatively easy: Add a servlet that is called with load-on-startup 1 so that it gets started early and can then initialize stuff on the system in it's init() method. As the deployers first deploy ejbs and then servlets, you should be good here to use the ejbs from within the servlet.

When the app shuts down, the servlet's destroy() method is (supposed to be) called, so you could shutdown stuff from there.

<servlet>
    <servlet-name>InitShutdownServlet</servlet-name>
    <display-name>Init Servlet</display-name>
    <servlet-class>com.acme.InitServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

Upvotes: 4

Related Questions