Java Quartz Memory Leak Message

I have a quartz job in my web application that runs a servlet. When I redistribute my application, I get the following message

[DefaultQuartzScheduler_Worker-5] but has failed to stop it. This is very likely to create a memory leak 

Also in production, there is a problem that the tomcat server does not stop after. /shutdown.sh, so we need to kill the process. In my opinion, it depends on the work of quartz, which cannot stop.

How can I stop a quartz job by redeploying my application or shutting down the server?

I am using tomcat 7, quartz 2.1.6 ...

  SchedulerFactory sf = new StdSchedulerFactory(); Scheduler scheduler = sf.getScheduler(); scheduler.start(); JobDetail job = JobBuilder.newJob(XYZJob.class).withIdentity("job1", "group1").build(); Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1","group1") .startNow() .withSchedule(CronScheduleBuilder.cronSchedule("0 0 1 * * ?")) .build(); scheduler.scheduleJob(job, trigger); 

As you can see, my work begins once a day. I do not see a place where I can check the flag to cancel the task.

+4
source share
2 answers

My solution was to change my configuration. I created quartz.properties

 org.quartz.scheduler.instanceName = XYZJob org.quartz.threadPool.threadCount = 1 org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore org.quartz.plugin.jobInitializer.class =org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin org.quartz.plugin.jobInitializer.fileNames = quartz-config.xml org.quartz.plugin.jobInitializer.failOnFileNotFound = true 

a quartz-config.xml

 <?xml version="1.0" encoding="UTF-8"?> <job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd" version="1.8"> <schedule> <job> <name>XYZJob</name> <group>XYZGroup</group> <description>Check the contracts idle period</description> <job-class>com.test.job.cron.XYZJob</job-class> </job> <trigger> <cron> <name>CronTriggerName</name> <job-name>XYZJob</job-name> <job-group>XYZGroup</job-group> <!-- It will run every day at 1 am --> <cron-expression>0 0 1 * * ?</cron-expression> </cron> </trigger> </schedule> 

and use QuartzInitializerServlet in my web.xml

 <servlet> <servlet-name>QuartzInitializer</servlet-name> <servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class> <init-param> <param-name>config-file</param-name> <param-value>quartz.properties</param-value> </init-param> <init-param> <param-name>shutdown-on-unload</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>start-scheduler-on-load</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> 

After shutting down my Tomcat, I get the following message

 INFO: QuartzInitializer: Quartz Scheduler successful shutdown. 
+4
source

Your work should be checked regularly (for example, at each iteration) if a stop is made. It is for you to implement this correctly in your work. Neither quartz nor Tomcat can help here (how should they stop the flow?).

You can set the flag in ServletContextListener , the contextDestroyed method. If the flag is set, the task should complete as soon as possible.

Quartz threads would otherwise endure the life of your web application! Therefore, updating your web application does not guarantee termination. I had problems with zombies waking up β€œsuddenly,” right after a new deployment. This is one of the few times when you simply do not believe your log files.

This is why you must kill Tomcat because there are threads that were not created by Tomcat.

+3
source

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


All Articles