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 a开发者_如何学Pythonnd EJB 3.0. Thanks.
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>
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
精彩评论