Spring + Quartz = memory leak

I use the following libraries.

  • quartz-2.2.1
  • spring -webmvc-3.2.9.RELEASE

on Apache Tomcat / 7.0.52 (Ubuntu).

I use Spring to configure Quartz.

@Configuration class QuartzConfig { @Bean FactoryBean<Scheduler> scheduler() { final SchedulerFactoryBean factory = new SchedulerFactoryBeanWithShutdownDelay(); final Map<String, Object> map = new LinkedHashMap<>(); map.put("settingsService", settingsService); final List<AbstractQuartzJob> jobs = new LinkedList<>(); jobs.add(dbBackupJob()); jobs.add(csvExportJob()); jobs.add(csvImportJob()); jobs.add(dbMaintenanceJob()); jobs.add(filesystemCleanupJob()); map.put("jobs", jobs); factory.setSchedulerContextAsMap(map); factory.setTriggers(new Trigger[] {cronTrigger}); return factory; } } 

I searched a lot today, why the tasks of the scheduler, where they do not close correctly ...

 Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-1] but has failed to stop it. This is very likely to create a memory leak. Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-2] but has failed to stop it. This is very likely to create a memory leak. Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-3] but has failed to stop it. This is very likely to create a memory leak. Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-4] but has failed to stop it. This is very likely to create a memory leak. Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-5] but has failed to stop it. This is very likely to create a memory leak. Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-6] but has failed to stop it. This is very likely to create a memory leak. Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-7] but has failed to stop it. This is very likely to create a memory leak. Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-8] but has failed to stop it. This is very likely to create a memory leak. Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-9] but has failed to stop it. This is very likely to create a memory leak. Jun 24, 2014 5:14:38 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/feeder##1.5.0] appears to have started a thread named [scheduler_Worker-10] but has failed to stop it. This is very likely to create a memory leak. 

The ugly hack was to write the SchedulerFactoryBeanWithShutdownDelay class.

 public class SchedulerFactoryBeanWithShutdownDelay extends SchedulerFactoryBean { private static final int SHUTDOWN_TIMEOUT = 2000; @Override public void destroy() throws SchedulerException { log.debug("Start shutdown of Quartz scheduler factory bean"); super.destroy(); try { log.debug("wait {}ms to shutdown Quartz", SHUTDOWN_TIMEOUT); Thread.sleep(SHUTDOWN_TIMEOUT); log.debug("Quartz scheduler shutdown completed"); } catch (InterruptedException e) { log.error("", e); } } } 

But this question should have been closed: https://jira.terracotta.org/jira/browse/QTZ-192

Did I make a mistake or can this be confirmed?

+6
source share
1 answer

great article about memory leak in Tomcat. Read the article, launch your web application, set Quartz tasks, then stop the web application, then grab the Tomcat JVM heap, load the heap in the Eclipse MAT and find out which classes are causing the memory leak. Then you can solve the problem.

+2
source

Source: https://habr.com/ru/post/971285/


All Articles