简体   繁体   English

使用 Oracle DB 在quartz 2.0.2 中查找属性出错

[英]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.我正在从石英版本 1.6.0 迁移到 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.它似乎工作正常,因为我可以看到数据在服务器启动时插入到我们的 oracle 数据库中的石英表中,并且石英调度程序设置也成功。

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).但是,当作业尝试第一次运行时,我遇到以下错误,即作业无法通过PropertyLoader从 DB 加载缓存属性,这些PropertyLoader是在服务器启动时设置的(Jboss 5.1)。
Below I am also getting one java.lang.IncompatibleClassChangeError as mentioned in stacktrace:下面我也得到一个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());
        }
    }

The problem is that you compiled your code with Quartz 1.6, where JobExecutionContext is a class.问题是您使用 Quartz 1.6 编译代码,其中JobExecutionContext是一个类。 But at runtime, you have Quartz 2+, where JobExecutionContext is actually an interface.但是在运行时,你有 Quartz 2+,其中JobExecutionContext实际上是一个接口。

If you can compile your code with Quartz 2.0, this issue should go away.如果你可以用 Quartz 2.0 编译你的代码,这个问题就会消失。

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.如果您正在构建一个可以同时使用 Quartz 1.6 和 2.0 的模块,您可能需要使用适配器解耦和隐藏 Quartz。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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