1

我想在一个项目中使用石英,但它似乎缺少一些功能。我需要的很简单,在完成执行后触发另一项工作。理想情况下,这将通过存储的触发器来完成,但石英只考虑基于时间的触发器,而不考虑其他类型的触发器。我正在为石英寻找某种工作依赖系统。

实际上应该有很多触发器,例如其他作业完成,文件正在修改,数据库表正在更新等。

这是一个等待 5 秒的作业:

public class JobA implements Job, JobListener {

public static final String LISTENER_NAME = "JobA";

public void execute(JobExecutionContext arg0) throws JobExecutionException {

    System.out.println("Job A, Waiting for 5 seconds");
    try {
        Thread.sleep(5L * 1000L);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    System.out.println("Done waiting");
}

public String getName() {
    return LISTENER_NAME;
}

public void jobExecutionVetoed(JobExecutionContext context) {
    //TODO
}

public void jobToBeExecuted(JobExecutionContext context) {
    String jobName = context.getJobDetail().getKey().toString();
    System.out.println("Job : " + jobName + " is going to start...");

}

public void jobWasExecuted(JobExecutionContext context,
        JobExecutionException jobException) {
    //      System.out.println("jobWasExecuted");

    String jobName = context.getJobDetail().getKey().toString();
    System.out.println("Job : " + jobName + " is finished...");

    if (!jobException.getMessage().equals("")) {
        System.out.println("Exception thrown by: " + jobName
                + " Exception: " + jobException.getMessage());
    }

    JobKey jobKey = new JobKey("JobA", "group1");
    try {
        context.getScheduler().triggerJob(jobKey);
    } catch (SchedulerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}
}

context.getScheduler().triggerJob(jobKey) 行根本不起作用。我试过添加完整的工作、递归工作,但似乎什么都做不了。使用此侦听器时如何获得另一份工作?

4

0 回答 0