How does Java monitor the start and stop of the Tomcat server?

Ideas: Use Java's @PostConstruct tag, @PreConstruct tag.

Principle: The method modified by @PostConstruct will run when the Tomcat server loads the servlet, that is, when the Tomcat server starts;

          The method modified by @PreConstruct will run when the Tomcat server unloads the servlet, that is, when the Tomcat server stops.

          Note: Stopping Tomcat in eclipse will not execute the method modified by @PreConstruct. You must manually shut down the Tomcat server in the bin folder in the Tomcat installation directory to execute the method modified by @PreConstruct.


Reference: https://blog.csdn.net/jimxiaoming/article/details/51556454

                 https://www.cnblogs.com/landiljy/p/5764515.html


            

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325912103&siteId=291194637