如何在jboss启动时实例化一个类

我想实例化我自己的java类(只有一次),当JBOSS 5和i的启动时间将使用该对象,直到我关闭jboss。

怎么可能实例化。

您可以使用ServletContextListener接口实现您的类,这使您的类能够在启动和关闭时从应用程序服务器(即JBoss)接收通知。

例如:

public class MyServletContextListener implements ServletContextListener { /**This method will run when the web application starts***/ public void contextInitialized(ServletContextEvent sce) { /**Put your codes inside , it will run when JBoss starts ***/ } } 

然后在web.xml注册MyServletContextListener

    com.abc.xyz.MyServletContextListener    

WAR格式打包应用程序并将其部署到JBoss中。 当JBoss启动时, MyServletContextListenercontextInitialized()也将运行。