Tomcat service start and stop monitoring

Source: Internet
Author: User

1: First need to import the package

2: Add a listener to Web. xml

3:

Servletcontextlistener Monitor ServletContext. The contextinitialized (Servletcontextevent SCE) method is fired when the ServletContext is created, and when ServletContext is destroyed, the contextdestroyed is fired ( Servletcontextevent sce) method.
With this listener, what do you want to do before Tomcat starts and stops?

 PackageCom.eoopen.listener;Importjava.util.List;Importjavax.servlet.ServletContextEvent;ImportJavax.servlet.ServletContextListener;Importorg.jivesoftware.smack.XMPPConnection;Importorg.jivesoftware.smack.XMPPException;Importorg.springframework.data.redis.core.RedisTemplate;Importcom.eoopen.util.Constant;ImportCom.eoopen.util.ContextUtil;Importcom.eoopen.util.XMPPConnectionUtils;ImportCom.eoopen.xmpp.loginin.ClientUser;ImportCom.eoopen.xmpp.loginin.ClientUserService;ImportCom.eoopen.xmpp.loginin.OfUser; Public classInitservletcontextlistenerImplementsservletcontextlistener{ Public voidcontextinitialized (Servletcontextevent sce) {System.out.println ("-------------------------contextinitialized"); Try {            //Create OpenFire connection, account loginXmppconnection connection =xmppconnectionutils.getconnection ();            Connection.login (Xmppconnectionutils.name, Xmppconnectionutils.password); //Initialize the openfire background login SessionIDXmppconnectionutils.loginbackstage (); //initializing the user cache queueInitusercachequeue (); } Catch(xmppexception e) {System.out.println ("------------------------------Server failed to initialize login OpenFire server");        E.printstacktrace (); }    }     Public voidcontextdestroyed (Servletcontextevent sce) {System.out.println ("--------------------------contextdestroyed");                    Xmppconnectionutils.closeconnection (); }    }

Tomcat service start and stop monitoring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.