简体   繁体   中英

Error in lookup property in quartz 2.0.2 with Oracle DB

I am migrating from quartz version 1.6.0 to 2.0.2. It seems to be working fine as I can see that data is inserted in quartz tables in our oracle DB on server start up and Quartz scheduler set up is also successful.

But, when jobs are trying their first run, I am getting below error where jobs are not able to load cached properties through PropertyLoader from DB, which were set up on server start up (Jboss 5.1).
Below I am also getting one java.lang.IncompatibleClassChangeError as mentioned in stacktrace:

    Error in the lookupProperty() java.lang.NullPointerException
    01/23 07:40:00,142 -STDERR- java.lang.NullPointerException
    01/23 07:40:00,142 -STDERR-     at com.qd.qhadmin.common.business.PropertyLoader.lookupProperty(PropertyLoader.java:36)
    01/23 07:40:00,142 -STDERR-     at com.qd.qehadmin.common.scheduler.MessageloadJob.execute(MessageloadJob.java:27)
    01/23 07:40:00,142 -STDERR-     at org.quartz.core.JobRunShell.run(JobRunShell.java:206)
    01/23 07:40:00,142 -STDERR-     at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:548)
    01/23 07:40:00,142 -STDERR- java.lang.NumberFormatException: null
    01/23 07:40:00,143 -STDERR-     at java.lang.Integer.parseInt(Integer.java:417)
    01/23 07:40:00,143 -STDERR-     at java.lang.Integer.<init>(Integer.java:660)
    01/23 07:40:00,143 -STDERR-     at com.qd.qehadmin.common.scheduler.MessageDownloadJob.execute(MessageDownloadJob.java:27)
    01/23 07:40:00,143 -STDERR-     at org.quartz.core.JobRunShell.run(JobRunShell.java:206)
    01/23 07:40:00,143 -STDERR-     at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:548)
    01/23 07:42:00,075 -org.quartz.core.JobRunShell- Job QH_QUARTZ.Mre match Job threw an unhandled Exception:
    java.lang.IncompatibleClassChangeError: Found interface org.quartz.JobExecutionContext, but class was expected
           at com.qd.qehadmin.common.scheduler.MREMatchJob.execute(MREMatchJob.java:129)
            at org.quartz.core.JobRunShell.run(JobRunShell.java:206)
            at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:548)
    01/23 07:42:00,078 -org.quartz.core.ErrorLogger- Job (QH_QUARTZ.Mre match Job threw an exception.
    org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.IncompatibleClassChangeError: Found interface org.quartz.JobExecutionContext, but class was expected]
            at org.quartz.core.JobRunShell.run(JobRunShell.java:217)
            at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:548)
    Caused by: java.lang.IncompatibleClassChangeError: Found interface org.quartz.JobExecutionContext, but class was expected
            at com.qd.qehadmin.common.scheduler.MREMatchJob.execute(MREMatchJob.java:129)
            at org.quartz.core.JobRunShell.run(JobRunShell.java:206)

-------Property loader code as below-----------
package com.qd.qhadmin.common.business;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import com.qd.qhadmin.common.database.PropertiesDAO;


public class PropertyLoader {

    private static Map<String,String> properties = null;
    private static PropertyLoader loader = null;
    private static Map<String,String> appXMLVersions = null;

    public static void init(){
        System.out.println("* * * * * * * * * * * * PropertyLoader START");
        loader = new PropertyLoader();
        try {
            loader.loadAppProp();
            loader.displayProp(properties, "Property");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("* * * * * * * * * * * * PropertyLoader FINISH");
    }

    public static String lookupProperty(String propName) {
        /*
         * Find property value by name
         */
        System.out.println("property Name is:::::"+propName);
        String propertyValue = null;
        try {
            if (properties.containsKey(propName.trim())) {
                propertyValue = (String) properties.get(propName.trim());
                System.out.println("property value is::::"+propertyValue);
            } else {
                System.out.println("PropertyLoader.lookupProperty() can't find this property: " + propName.trim());
            }
        } catch (Exception f) {
            System.out.println("Error in the lookupProperty() " + f);
            f.printStackTrace();
        }
        return propertyValue;
    }
    private void displayProp(Map hm, String refDataType) throws Exception {
        TreeMap tm = new TreeMap(hm);
        Set keyset = tm.keySet();
        Iterator it = keyset.iterator();
        String name = "", value = "";
        while (it.hasNext()) {
            name = ((String) it.next()).toUpperCase();
            if (name.contains("PASSWORD") || name.contains("SECKEY")){
                value = "********";
            }else if (name.contains("APPER_AP")){
                value = (String) hm.get(name);
                value = value.substring(0, 10) + "*************";
            }
            else{
                value = (String) hm.get(name);
            }
            System.out.println(refDataType + " " + name + " = " + value);
        }
    }

    private void loadAppProp() throws Exception {
        java.net.InetAddress in = java.net.InetAddress.getLocalHost();
        String hostname = in.getHostName();
        properties = getProperties(hostname);
    }

    private Map<String,String> getProperties(String groupName) {
        Map<String,String> properties = new HashMap<String,String>();
        PropertiesDAO dao = new PropertiesDAO();
        properties = dao.getProperties();
        return properties;
    }

    public static void main(String[] args) {
        PropertyLoader loader = new PropertyLoader();
    }

}


--------Mre match code----------------

public void execute(JobExecutionContext ctx) throws JobExecutionException
    {
        LogFile.MRE_MATCH_JOB.logInfo("***MRE Match Job starting*** ", this.getClass().getName());

        try{        
            //Scheduler scheduler = new StdSchedulerFactory().getScheduler();           

                LogFile.MRE_MATCH_JOB.logInfo("MMRE jobs size  : "+ctx.getScheduler().getCurrentlyExecutingJobs().size(), this.getClass().getName());   
                initWrapperClient();                    
                startTime=System.currentTimeMillis();                   
                mmreMatch();
                endTime=System.currentTimeMillis();
                LogFile.MRE_MATCH_JOB.logInfo("***MRE Match job ends*** Loadtest: "+Constants.loadTest+" in time: "+(endTime-startTime)/1000 + "secs", this.getClass().getName());

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

The problem is that you compiled your code with Quartz 1.6, where JobExecutionContext is a class. But at runtime, you have Quartz 2+, where JobExecutionContext is actually an interface.

If you can compile your code with Quartz 2.0, this issue should go away.

If you are building a module that should work with both Quartz 1.6 and 2.0, you will probably need to decouple and hide Quartz with an adapter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM