使用Oracle DB在quartz 2.0.2中的lookup属性出错

时间:2018-01-23 08:06:43

标签: java quartz-scheduler

我正从石英版1.6.0迁移到2.0.2。它看起来工作正常,因为我可以看到数据插入到服务器启动时我们的oracle DB中的石英表中,并且Quartz调度程序设置也是成功的。

但是,当作业尝试第一次运行时,我遇到错误,其中作业无法通过PropertyLoader从DB加载缓存属性,这是在服务器启动时设置的(Jboss 5.1)。登记/> 下面我还得到了一个{stack}的提到java.lang.IncompatibleClassChangeError

    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());
        }
    }

1 个答案:

答案 0 :(得分:0)

问题是您使用Quartz 1.6编译了代码,其中JobExecutionContext是一个类。但是在运行时,您拥有Quartz 2+,其中JobExecutionContext实际上是一个接口。

如果您可以使用Quartz 2.0编译代码,则此问题将消失。

如果您要构建一个可与Quartz 1.6和2.0一起使用的模块,则可能需要使用适配器解耦和隐藏Quartz。