Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Quartz Memory leak message

i have an quartz job in my web-application, which is started by an servlet. When i redeploy my application i get following message

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

Also in production we have the problem that the tomcat-server doesn't stop after ./shutdown.sh, so that we have to kill the process. In my opinion it depence on the quartz job, that can't stop.

How can i stop the quartz job by redeploy my application or shutdown the server?

I use 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 job starts one time per day. I don't see an point where i can check an flag, to cancel the job.

like image 313
Tim Avatar asked Mar 24 '23 08:03

Tim


1 Answers

My solution was to change my configuration. I created an 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 the 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 shutdown my Tomcat, i get the following message

INFO: QuartzInitializer: Quartz Scheduler successful shutdown.
like image 172
Tim Avatar answered Apr 02 '23 19:04

Tim