本文介绍了使用 Oracle DB 在quartz 2.0.2 中查找属性时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

但是,当作业尝试第一次运行时,我遇到以下错误:作业无法通过 PropertyLoader 从数据库加载缓存属性,这些属性是在服务器启动时设置的 (Jboss 5.1).
下面我也得到一个 java.lang.IncompatibleClassChangeError 如堆栈跟踪中提到的:

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

推荐答案

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

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.

如果你可以用 Quartz 2.0 编译你的代码,这个问题就会消失.

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

如果您正在构建一个可以同时使用 Quartz 1.6 和 2.0 的模块,您可能需要使用适配器解耦和隐藏 Quartz.

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.

这篇关于使用 Oracle DB 在quartz 2.0.2 中查找属性时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 01:08