无法运行Quartz例4

时间:2015-12-24 14:39:09

标签: java quartz-scheduler

我尝试将参数传递给我的作业类。我发现this example,并不是很好;我认为这很有帮助,但是,有些步骤没有解释。 他们写的行不是正确的顺序(特别是对于作业类),他们创建了两次变量“data”(!!?)。 也许,据我所知,我必须自己组织和完成细节。

...但问题不在这里,我已粘贴示例,完成并运行它,然后发生错误。

首先,这条消息:

79 [MyScheduler_QuartzSchedulerThread] ERROR org.quartz.core.ErrorLogger  - An error occured instantiating job to be executed. job= 'group1.job'

然后,更大,但可能是由第一条消息引起的。

其他问题,为什么控制台会给我这个消息:

 [MyScheduler_QuartzSchedulerThread] DEBUG org.quartz.core.QuartzSchedulerThread  - batch acquisition of 0 triggers

您是否成功运行此示例?

编辑:我已经压制了所有程序,所以我现在写了它,我认为这是错误:

[MyScheduler_QuartzSchedulerThread] ERROR org.quartz.core.ErrorLogger  - An error occured instantiating job to be executed. job= 'group1.job1'
org.quartz.SchedulerException: Problem instantiating class 'com.searchengine.lms.admin.jdbc.MysqlJob' -  [See nested exception: java.lang.NullPointerException]
    at org.quartz.core.JobRunShell.initialize(JobRunShell.java:134)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:375)
Caused by: java.lang.NullPointerException
    at org.quartz.simpl.PropertySettingJobFactory.setBeanProps(PropertySettingJobFactory.java:98)
    at org.quartz.simpl.PropertySettingJobFactory.newJob(PropertySettingJobFactory.java:76)
    at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127)
    ... 1 more
69   [MyScheduler_QuartzSchedulerThread] INFO  org.quartz.simpl.RAMJobStore  - All triggers of Job group1.job1 set to ERROR state.
69   [MyScheduler_QuartzSchedulerThread] DEBUG org.quartz.core.QuartzSchedulerThread  - batch acquisition of 0 triggers

编辑:

import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;

public class MysqlScheduler{

    public static void main(String[] args) throws SchedulerException, InterruptedException{

        //Voir les examples proposés par quartz-scheduler.org notamment sur les job parameters et job state
        SchedulerFactory sf = new StdSchedulerFactory();
        Scheduler sched = sf.getScheduler();

        JobDetail job1 = newJob(MysqlJob.class)
                .withIdentity("job1", "group1")
                .build();

            SimpleTrigger trigger1 = newTrigger() 
                .withIdentity("trigger1", "group1")
                .withSchedule(simpleSchedule()
                        .withIntervalInSeconds(10)
                        .withRepeatCount(4))
                .build();
//          job1.getJobDataMap().put(MysqlJob.FAVORITE_COLOR, "Green");
//          job1.getJobDataMap().put(MysqlJob.EXECUTION_COUNT, 1);
//          sched.scheduleJob(job1, trigger1);
            sched.start();
            Thread.sleep(60L * 1000L);
            sched.shutdown(true);
    }
}

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;

@PersistJobDataAfterExecution
@DisallowConcurrentExecution 
public class MysqlJob implements Job{   

//  static final String FAVORITE_COLOR = null;
//  static final String EXECUTION_COUNT = null;
//  int counter = 1;
    public void execute(JobExecutionContext context) throws JobExecutionException {
        //Ici placer les tâches à effectuer
        System.out.println("A");
//      JobDataMap data = context.getJobDetail().getJobDataMap();
//      int count = data.getInt(EXECUTION_COUNT);
//      count++;
//      data.put(EXECUTION_COUNT, count);



    }
}

0 个答案:

没有答案