Spring consolidation quartz off, memory leaks when shutting down Tomcat servlet containers

Source: Internet
Author: User

Error message

22-sep-2017 06:19:51.064 WARNING [main] Org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads the Web application [license] appears to has started a thread named [ Org.springframework.scheduling.quartz.schedulerfactorybean#0_worker-1] but had failed to stop it. This was very likely to create a memory leak. StackTraceof Thread:java. lang. Object.wait (Native Method)org. Quartz.simpl.simplethreadpool$workerthread.Run(simplethreadpool.java:568) 22-sep-2017 06:19:51.065 WARNING [main] Org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads the Web application [license] appears to has Started a thread named [Org.springframework.scheduling.quartz.schedulerfactorybean#0_worker-2] but have failed to stop it . This was very likely to create a memory leak. StackTraceof Thread:java. lang. Object.wait (Native Method)org. Quartz.simpl.simplethreadpool$workerthread.Run(simplethreadpool.java:568) 22-sep-2017 06:19:51.065 WARNING [main] Org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads the Web application [license] appears to has Started a thread named [org.springframework.scheduling.quartz.schedulerfactorybean#0_worker-3] but have failed to stop it . This was very likely to create a memory leak. StackTraceof Thread:java. lang. Object.wait (Native Method)org. Quartz.simpl.simplethreadpool$workerthread.Run(simplethreadpool.java:568) 22-sep-2017 06:19:51.068 WARNING [main] Org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads the Web application [license] appears to has Started a thread named [org.springframework.scheduling.quartz.schedulerfactorybean#0_worker-4] but have failed to stop it . This was very likely to create a memory leak. StackTraceof Thread:java. lang. Object.wait (Native Method)org. Quartz.simpl.simplethreadpool$workerthread.Run(simplethreadpool.java:568) 22-sep-2017 06:19:51.069 WARNING [main] Org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads the Web application [license] appears to has Started a thread named [org.springframework.scheduling.quartz.schedulerfactorybean#0_worker-5] but have failed to stop it . This was very likely to create a memory leak. StackTraceof Thread:java. lang. Object.wait (Native Method)org. Quartz.simpl.simplethreadpool$workerthread.Run(simplethreadpool.java:568) 22-sep-2017 06:19:51.070 WARNING [main] Org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads the Web application [license] appears to has Started a thread named [org.springframework.scheduling.quartz.schedulerfactorybean#0_worker-6] but have failed to stop it . This was very likely to create a memory leak. StackTraceof Thread:java. lang. Object.wait (Native Method)org. Quartz.simpl.simplethreadpool$workerthread.Run(simplethreadpool.java:568) 22-sep-2017 06:19:51.071 WARNING [main] Org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads the Web application [license] appears to has Started a thread named [org.springframework.scheduling.quartz.schedulerfactorybean#0_worker-7] but have failed to stop it . This was very likely to create a memory leak. StackTraceof Thread:java. lang. Object.wait (Native Method)org. Quartz.simpl.simplethreadpool$workerthread.Run(simplethreadpool.java:568) 22-sep-2017 06:19:51.072 WARNING [main] Org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads the Web application [license] appears to has Started a thread named [Org.springframework.scheduling.quartz.schedulerfactorybean#0_worker-8] but have failed to stop it . This was very likely to create a memory leak. StackTraceof Thread:java. lang. Object.wait (Native Method)org. Quartz.simpl.simplethreadpool$workerthread.Run(simplethreadpool.java:568) 22-sep-2017 06:19:51.073 WARNING [main] Org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads the Web application [license] appears to has Started a thread named [org.springframework.scheduling.quartz.schedulerfactorybean#0_worker-9] but have failed to stop it . This was very likely to create a memory leak. StackTraceof Thread:java. lang. Object.wait (Native Method)org. Quartz.simpl.simplethreadpool$workerthread.Run(simplethreadpool.java:568) 22-sep-2017 06:19:51.080 WARNING [main] Org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads the Web application [license] appears to has Started a thread named [org.springframework.scheduling.quartz.schedulerfactorybean#0_worker-10] but have failed to stop It. This was very likely to create a memory leak. StackTraceof Thread:java. lang. Object.wait (Native Method)

Problem Analysis: The servlet container is closed when the quartz timer thread is still executing, it is at a loss, do not know how to do only forcibly shut down.

Solve the idea, in the Contextdestroyed event when closing the container to detect the ServletContext quartz related properties, find the bean and then call it to end the method.

Workaround:

ImportJava.sql.Driver;ImportJava.sql.DriverManager;Importjava.sql.SQLException;Importjava.util.Enumeration;Importjavax.servlet.ServletContextEvent;ImportJavax.servlet.ServletContextListener;Importjavax.servlet.ServletRequestEvent;ImportJavax.servlet.ServletRequestListener;ImportJavax.servlet.annotation.WebListener;Importjavax.servlet.http.HttpSessionEvent;ImportJavax.servlet.http.HttpSessionListener;ImportOrg.apache.logging.log4j.web.Log4jWebSupport;ImportOrg.quartz.impl.StdScheduler;ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;ImportOrg.springframework.web.context.WebApplicationContext;Importorg.springframework.web.context.support.WebApplicationContextUtils; @WebListener Public classAppcontextlistenerImplementsservletcontextlistener{ Public voidcontextdestroyed (Servletcontextevent event) {Logger.info ("Destroying Context ..."); Try{Webapplicationcontext Context=(Webapplicationcontext) Event.getservletcontext (). getattribute (Webapplicationcontext.root_web_applicati                    On_context_attribute); Enumeration<String> attributes =Event.getservletcontext (). Getattributenames ();  while(Attributes.hasmoreelements ()) {String attr=attributes.nextelement (); Object prop=Event.getservletcontext (). getattribute (attr); Logger.info ("Attribute.name: {},class:{}, value:{}", Attr,prop.getclass (). GetName (), prop); } string[] Beannames=Context.getbeandefinitionnames ();  for(String beanname:beannames) {Object Bean=Context.getbean (beanname); Logger.info ("Found Bean attribute in servletcontext,name:{},class:{},value:{}", Beanname,bean.getclass (). GetName (), Bean); if(Beanname.contains ("quartz") &&beanname.contains ("Scheduler")) {Stdscheduler Scheduler= (Stdscheduler) context.getbean ("Org.springframework.scheduling.quartz.schedulerfactorybean#0"); Logger.info ("Discover Quartz timed Tasks"); Logger.info ("Beanname:{},classname:{}", Scheduler,scheduler.getclass (). GetName ()); if(scheduler.isstarted ()) {Logger.info ("Quartz:waiting for job complete ..."); Scheduler.shutdown (true); Logger.info ("Quartz:all threads is complete and exited ..."); }          }          }                } Catch(Exception e) {logger.error ("Error destroying Context", E); }    }    //https://stackoverflow.com/questions/23936162/register-shutdownhook-in-web-application     Public voidcontextinitialized (Servletcontextevent event) {//ServletContext context = Event.getservletcontext (); //system.setproperty ("RootPath", Context.getrealpath ("/")); //Loggercontext CTX = (Loggercontext) Logmanager.getcontext (false); //ctx.reconfigure ();          /*logger.info ("Global setting,rootpath:{}", RootPath);  Logger.info ("Deployed on Architecture:{},operation system:{},version:{}", System.getproperty ("Os.arch"),           System.getproperty ("Os.name"), System.getproperty ("os.version"));           Debugger.dump (); Logger.info ("App startup completed ....");*/    }|

Close the Tomcat log as follows:

Spring consolidation quartz off, memory leaks when shutting down Tomcat servlet containers

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.