Java web application in a Servlet container vs. standalone

前端 未结 6 852
悲哀的现实
悲哀的现实 2021-01-01 10:00

What are the advantages of building a small Java web app to run in a Servlet container (like Tomcat) vs. building a standalone Java app with a built-in web server and runnin

6条回答
  •  渐次进展
    2021-01-01 10:25

    if you are having issues with your hot deploy, most likely you aren't cleaning up your external connections or other resources. To handle this, usually you want to implement a listener that will let you know when something is started or stopped.

    you should probably in your wars implement something like this (tomcat 6):

    public class MyTomcatInitCleanupListener implements ServletContextListener
    {
        @Override
        public void contextInitialized(ServletContextEvent arg0)
        {
            super.contextInitialized(arg0);
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent arg0)
        {
            super.contextDestroyed(arg0);
        }
    }
    

    for tomcat 7+, you can google "tomcat lifecycle listener"

提交回复
热议问题