I am inquiring about how to solve the job execution delay in the java quartz library.

Asked 2 years ago, Updated 2 years ago, 78 views

There is a delay in the execution of the schedule on a weekly basis for the schedule registered using the Java quartz library.

There is no noticeable error message, you can see the delay in the log for a specific schedule, and the result of the API failure to run for the delayed schedule is repeated every week.

On the source, the synchronized(){} processed part is the actual api to be executed.

I would like to get help with structural problem solving or improvement measures.

Thank you.

[2016-04-11 07:05:00] INFO  [JobWorker.java:39] IT_Daily_ilji started...(Period)
[2016-04-11 08:55:15] INFO  [JobWorker.java:52] IT_Daily_ilji ended...(Period)

[2016-04-12 07:05:00] INFO  [JobWorker.java:39] IT_Daily_ilji started...(Period)
[2016-04-12 07:19:10] INFO  [JobWorker.java:52] IT_Daily_ilji ended...(Period)
[2016-04-13 07:05:00] INFO  [JobWorker.java:39] IT_Daily_ilji started...(Period)
[2016-04-13 07:17:11] INFO  [JobWorker.java:52] IT_Daily_ilji ended...(Period)
[2016-04-14 07:05:00] INFO  [JobWorker.java:39] IT_Daily_ilji started...(Period)
[2016-04-14 07:17:25] INFO  [JobWorker.java:52] IT_Daily_ilji ended...(Period)
[2016-04-15 07:05:00] INFO  [JobWorker.java:39] IT_Daily_ilji started...(Period)
[2016-04-15 07:18:33] INFO  [JobWorker.java:52] IT_Daily_ilji ended...(Period)
[2016-04-16 07:05:00] INFO  [JobWorker.java:39] IT_Daily_ilji started...(Period)
[2016-04-16 07:19:09] INFO  [JobWorker.java:52] IT_Daily_ilji ended...(Period)
[2016-04-17 07:05:00] INFO  [JobWorker.java:39] IT_Daily_ilji started...(Period)
[2016-04-17 07:19:16] INFO  [JobWorker.java:52] IT_Daily_ilji ended...(Period)

[2016-04-18 07:05:00] INFO  [JobWorker.java:39] IT_Daily_ilji started...(Period)
[2016-04-18 08:48:25] INFO  [JobWorker.java:52] IT_Daily_ilji ended...(Period)
public void execute(JobExecutionContext context)throws JobExecutionException{

        JobDataMap dataMap = context.getJobDetail().getJobDataMap();

        String reportFile = dataMap.getString("ReportFile");
        String reportName = dataMap.getString("ReportName");
        String groupName = dataMap.getString("GroupName");
        String reportSys = dataMap.getString("REPORT_SYS");


        logger.info(reportName + " started...(Period)");

        synchronized(JobWorker.class){  
            Creater creater = new Creater(reportName, reportSys);
            //creater.setLogger(logger);
            if(reportSys.equals("RD"))
                creater.rdrun();
            else
                creater.run();
        }

        logger.info(reportName + " ended...(Period)");
    }
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.1
Created-By: 1.3.1_07-b02 (Sun Microsystems Inc.)
Built-By: jhouse
Main-Class: org.quartz.helpers.VersionPrinter
Sealed: false

Name: quartz
Implementation-Title: Quartz
Implementation-Version: 1.4.5 March 13 2005
Implementation-Vendor: The Quartz project developers.
Implementation-Vendor-URL: http://www.quartzscheduler.org
Specification-Title: Quartz
Specification-Version: 1.4
Specification-Vendor: The Quartz project developers.
Specification-Vendor-URL: http://www.quartzscheduler.org
Sealed: false

The date is different, but the log corresponds to the Monday before that.

[2016-04-04 07:05:00] INFO  [JobWorker.java:39] IT_Daily_ilji started...(Period)
[2016-04-04 08:40:55] INFO  [Creater.java:125] [IT_Daily_ilji]Report Create start...(Period)
[2016-04-04 08:40:55] INFO  [Creater.java:587] [IT_Daily_ilji]Check gc.getTime :Sun Apr 03 08:40:55 KST 2016
[2016-04-04 08:40:55] INFO  [Creater.java:396] [IT_Daily_ilji]rptEndTime  : 20160403  rptStartTime : 20160403 Date ds : null rptFormat : pdf^xls^html^rtf^
[2016-04-04 08:40:55] INFO  [JasperRunner.java:114] [IT_Daily_ilji]JVM cmd : ...............................................
[2016-04-04 08:40:56] INFO  [JasperRunner.java:121] [IT_Daily_ilji]< PeriodicExporterJVM ... START >

java quartz

2022-09-21 20:07

1 Answers

It seems to be a problem in the synchronized(JobWorker.class) section.

If your goal is to make this part into a critical section, change it to a concurrent package and test it.

// java.util.concurrent.locks on the class member.Declare Reentrant Lock
static ReentrantLock critical = new ReentrantLock(); 

public void execute(JobExecutionContext context)throws JobExecutionException{

    // ... omission
    // // Critical Section
    critical.lock();
    // Only one thread passed at a time.
    // Please refer to tryLock() if you are already performing or want to exit.
    try {
            Creater creater = new Creater(reportName, reportSys);
            //creater.setLogger(logger);
            if(reportSys.equals("RD"))
                creater.rdrun();
            else
                creater.run();        
    } } finally
        critical.unlock();
    }

}


2022-09-21 20:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.