History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: QUARTZ-25
Type: Bug Bug
Status: Closed Closed
Resolution: Cannot Reproduce
Priority: Major Major
Assignee: James House
Reporter: Zhe Liu
Votes: 2
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Quartz Scheduler

Multiple job threads for a single job

Created: 18/Jun/04 12:16 PM   Updated: 20/Dec/04 03:04 PM
Component/s: Core
Affects Version/s: 1.4.1
Fix Version/s: 1.4.3

Environment: Win Xp, JDK1.4.2, Eclipse, Quartz1.4.0


 Description  « Hide
I got this problem when I use quartz1.4.0 and try to use the JobInitializationPlugin. Here is the jobs.xml.

<?xml version="1.0" encoding="utf-8"?>
<quartz>
<job>
<job-detail>
<name>job1</name>
<group>group1</group>
<job-class>com.test.DumbJob1</job-class>
<durability>true</durability>
<volatility>false</volatility>
<recover>true</recover>
</job-detail>
<trigger>
<simple>
<name>trigger1</name>
<group>group1</group>
</simple>
</trigger>
</job>
<job>
<job-detail>
<name>job2</name>
<group>group1</group>
<job-class>com.test.DumbJob2</job-class>
<durability>true</durability>
<volatility>false</volatility>
<recover>true</recover>
</job-detail>
<trigger>
<simple>
<name>trigger2</name>
<group>group1</group>
</simple>
</trigger>
</job>
</quartz>

Both DumbJob1 and DumbJob2 implement StatefulJob interface and they won't stop until the abort() is called. After the scheduler starts, it will wait for 30 secs. Before the scheduler is shutdown, abort() will be called so that these jobs will be stopped.

The problem is when the schedulers starts, there will be FOUR jobs running, two for DumbJob1 and two for DumbJob2. If I use quartz1.3.4, there will be only two jobs.

BTW, I commented out #org.quartz.plugin.jobInitializer.scanInterval = 10
in the property file (default should be 0 according to the javadoc).


 All   Comments   Change History      Sort Order:
James House - [18/Jun/04 12:44 PM ]

Can you post the source of the DubJob classe(s)?

Or at least describe in detail what the jobs do, and what abort() does?

thanks,
james

(Also a complete test application for replicating the problem would be good).


Zhe Liu - [12/Jul/04 01:12 PM ]
Thanks for the reply. I didn't notice the comments before and sorry for the late response.

I created a testcase.

This is the implementation of DumbJob.
===============================================================
package com.test.quartz;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;

public class DumbJob implements StatefulJob
{
    private boolean running = false;

/* (non-Javadoc)
     * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
     */
    public void execute(JobExecutionContext context)
        throws JobExecutionException
    {
        running = true;
        System.out.println("Start executing");
        while (running)
        {
            System.out.println("running...");
            try
            {
                Thread.sleep(10 * 1000L);
            }
            catch (InterruptedException ie)
            {
            }
        }
        System.out.println("Job aborted");
    }

/**
     * To be called to stop the job.
     *
     * @throws JobExecutionException
     */
    public void abort() throws JobExecutionException
    {
        System.out.println("Trying to abort...");
        running = false;
    }
}
============================================================
This is jobs.xml

============================================================
<?xml version="1.0" encoding="utf-8"?>
<!--
<quartz xmlns="http://www.quartzscheduler.org/ns/quartz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.quartzscheduler.org/ns/quartz http://www.quartzscheduler.org/ns/quartz/job_scheduling_data_1_1.xsd" version="1.1">
-->
<quartz>
<job>
<job-detail>
<name>job1</name>
<group>group1</group>
<job-class>com.test.quartz.DumbJob</job-class>
<durability>true</durability>
<volatility>false</volatility>
<recover>true</recover>
</job-detail>
<trigger>
<simple>
<name>trigger1</name>
<group>group1</group>
</simple>
</trigger>
</job>
</quartz>
============================================================
This is part of the code to start/stop scheduler:
============================================================

lg.info("------- Initializing -------------------");

Scheduler sched = sf.getScheduler();

lg.info("------- Initialization Complete -----------");

sched.start();

lg.info("------- Started Scheduler -----------------");

lg.info("------- Waiting 30 Secs... -----------------------");

try
        {
            Thread.sleep(30L * 1000L); // wait 30 seconds to show jobs
            // executing...
        }
        catch (Exception e)
        {
        }

lg.info("------- To stop Job... -----------------------");


        List jobs = sched.getCurrentlyExecutingJobs();
        Iterator iter = jobs.iterator();

while (iter.hasNext())
        {
            JobExecutionContext jec = (JobExecutionContext) iter.next();
            Job currentJob = jec.getJobInstance();
if (currentJob instanceof DumbJob)
{
DumbJob dumbJob = (DumbJob) currentJob;
dumbJob.abort();
}
        }

lg.info("------- Waiting 20 Secs... -----------------------");
        try
        {
            Thread.sleep(20L * 1000L);
            // executing...
        }
        catch (Exception e)
        {
        }

lg.info("------- Shutting Down ---------------------");

sched.shutdown();

lg.info("------- Shutdown Complete -----------------");

SchedulerMetaData metaData = sched.getMetaData();
        lg.info("Executed " + metaData.numJobsExecuted() + " jobs.");
=====================================================================
From the log, I can see that DumbJob was called twice and it will print "Executed 2 jobs" in the end.

The problem only exists if I use jdbc job store and before running the program, I deleted content in all quartz database tables.

Please let me know if you need more info.

Thanks,
Zhe

Zhe Liu - [26/Jul/04 01:17 PM ]
I downloaded and tested on quartz1.4.1. The same problem exists.

Sheryl Philip - [03/Aug/04 12:36 AM ]
Hi,
 I have the same problem with Quartz 1.4.0. Has anyone solved this problem of running 2 jobs instead of one?
 Could anyone help me out !!!

Var George - [04/Aug/04 06:36 PM ]
could some one in Quartz please give some suggestion. We have this problem in quartz 1.4.1 as well. Can we expect a fix soon?

Dev - [09/Sep/04 02:14 PM ]
This causes problem while using in enterprise application where cluster is a must.

James Shen - [28/Sep/04 11:23 PM ]
I have the same problem in quartz 1.4.2. Is there any known solution to fix this? Is it planned to be fixed anytime soon?

I didn't quiet understand Dev's comment. Does it mean that I need to run Quartz in cluster in order to fix this problem? Could you please point me to information on how to do it?

James House - [20/Dec/04 03:04 PM ]
I've tried and tried to reproduce this, including with the example code, and cannot get it to run more than the one job.