Quartz job getting triggered at wrong times

992 views Asked by At

Issue Description: We are having a quartz job which is scheduled to run at different times during the day say 1PM and 4PM and 7PM. Issue is that the job is getting triggered and executed on times other than the scheduled times also.

What we did: We have already tried shutting down our servers completely (JBoss) and clearing quartz tables but that hasn't worked at all.

We are using quartz 1.6 and I want to know, if there is any bug in the version and if quartz upgrade can resolve the issue OR If there is any problem with setting up quartz properties and if properties can be tweaked to resolve this.

Edit - more details below:

I have corrected the job timings now. Also, job is getting triggered at any random times other than these we mentioned in its schedule. There is no pattern in when it is getting triggered apart from the scheduled times.

Below are the job and trigger details in DB properties file. Based on these job details and trigger details will be set up in DB in Quartz_Triggers and Quartz_CronTrigger tables:

<job>
        <job-detail>
            <name>Match Job</name>
            <group>JB_QUARTZ</group>
            <job-class>com.qd.qehadmin.common.scheduler.MatchJob</job-class>
            <volatility>false</volatility>
            <durability>true</durability>
            <recover>true</recover>
        </job-detail>
        <trigger>
            <cron>
                <name>Match Job Trigger</name>
                <group>JB_QUARTZ</group>
                <job-name>match Job</job-name>
                <job-group>JB_QUARTZ</job-group>
                <cron-expression>0 0 13,16,19 * * ?</cron-expression>
            </cron>
        </trigger>
    </job>

Below are the quartz properties details in DB:

# Configure Main Scheduler Properties  
#============================================================================
org.quartz.scheduler.instanceName = JB_QUARTZ
org.quartz.scheduler.instanceId = AUTO
#============================================================================
# Configure ThreadPool  
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
#============================================================================
# Configure JobStore  
#============================================================================
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties = true
org.quartz.jobStore.dataSource = jobSchedulerDS
org.quartz.jobStore.tablePrefix = JB_QRTZ_
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 10000
#============================================================================
# Configure Datasources
#============================================================================
org.quartz.dataSource.jobSchedulerDS.jndiURL=java:JBAPI
org.quartz.dataSource.jobSchedulerDS.java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
#java.naming.provider.url=jnp://localhost:3099
java.naming.provider.url=jnp://166.20.337.12:8441,166.20.337.14:8441,166.20.337.16:8441,166.20.337.19:8441
#============================================================================

Below is the Java code for job:

public void execute(JobExecutionContext ctx) throws JobExecutionException
    {

        try{        
            //Scheduler scheduler = new StdSchedulerFactory().getScheduler();           
            SendEmail sm = new SendEmail();     
            boolean running = false;            

                if (ctx.getJobDetail().getKey().getName().equalsIgnoreCase("match Job") ) { 
                    LogFile.MATCH_JOB.logInfo("Match jobs size  : "+ctx.getScheduler().getCurrentlyExecutingJobs().size(), this.getClass().getName());  
                    if(ctx.getScheduler().getCurrentlyExecutingJobs().size()==1)
                    {
                    initClient(); //This method will read properties from DB                    
                    startTime=System.currentTimeMillis();                   
                    Match(); //This method will execute job level code  
                    endTime=System.currentTimeMillis();

                    LogFile.MATCH_JOB.logInfo("***Match job ends*** Loadtest: "+Constants.loadTest+" in time: "+(endTime-startTime)/1000 + "secs", this.getClass().getName());
                }
                    else
                    {
                        running=true;  
                    } 
                }


            if(running)  
            { 
                LogFile.MATCH_JOB.logInfo("The Match job is already running – sending email",this.getClass().getName());
                sm.sendEmail();
            }       

        }catch(Exception e){
            e.printStackTrace();
            LogFile.MATCH_JOB.logError("***Match Job Error*** " +e.getStackTrace(), this.getClass().getName());
        }
    }
0

There are 0 answers