石英作业调度器使用Java,在待机模式中无法执行作业。

huangapple go评论71阅读模式
英文:

Quartz job scheduler using Java, stuck on standby mode without the job being executed

问题

我有一个类在这个类中我执行一些操作我想创建一个定时任务来自动处理这个操作例如每隔 x 分钟执行一次
我正在使用 Quartz这个类实现了 Job 接口在我的驱动类中我创建了我的 JobDetail调度器scheduler和触发器trigger),然后启动它然而这个任务没有被执行日志信息如下

    没有启动
    当前处于待命模式
    已执行的任务数0

驱动类中调度器的代码

    try {
               
        JobDetail job = JobBuilder.newJob(TestMkFPMJob.class).withIdentity("TestMkFPMJob").build();
        Trigger trigger = TriggerBuilder.newTrigger().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(Integer.parseInt(strTimeSched)).repeatForever()).build();
        
        SchedulerFactory schFactory = new StdSchedulerFactory();
        Scheduler sch = schFactory.getScheduler();
        sch.start();
        sch.scheduleJob(job, trigger);

    } catch (SchedulerException e) {
        e.printStackTrace();
        System.out.println("调度器错误");
    }

这里的 "TestMkFPMJob" 是处理操作的任务类strTimeSched 已经被获取并设置为 120获取自……

我已经寻找类似的问题但似乎没有找到任何进展的提示非常感谢任何帮助
请注意这是我第一次使用 Quartz/任务调度
英文:

i have a class where i perform some activities, and i want to create a job that will handle this operation automatically, scheduled every x minutes for example.
I am using Quartz, this class implements Job, and in my driver class i'm creating my jobdetail, scheduler and trigger and then starting it. However, the job isn't being executed, log info :

    NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0

The code for the scheduler in my driver class:

try {
           
        JobDetail job = JobBuilder.newJob(TestMkFPMJob.class).withIdentity("TestMkFPMJob").build();
        Trigger trigger = TriggerBuilder.newTrigger().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(Integer.parseInt(strTimeSched)).repeatForever()).build();
      

        SchedulerFactory schFactory = new StdSchedulerFactory();
        Scheduler sch = schFactory.getScheduler();
        sch.start();
        sch.scheduleJob(job, trigger);

            } 
      catch (SchedulerException e)
      {
        e.printStackTrace();
        System.out.println("Scheduler Error");
      }

With "TestMkFPMJob" being the job class where my operations are handled, and strTimeSched is already fetched and set as 120 fetched from

I've been looking for a similar issue but can't seem to find any tip to move forward, appreciate any.
Please note that this is my first time using Quartz/Job scheduling.

答案1

得分: 5

以下是您要翻译的内容:

具有“NOT STARTED”状态的日志条目是误导性的,因为每当创建QuartzScheduler实例时都会显示该状态。这并不意味着作业未在运行。它是在执行Scheduler sch = schFactory.getScheduler();这一行后,以及在接下来的一行中启动调度器后编写的。

如果我采用您的示例在我的计算机上运行它,它会按预期工作:

public class Quartz {

    public static void main(String[] args) {
        try {

            JobDetail job = JobBuilder.newJob(MyJob.class).withIdentity("myJob").build();
            Trigger trigger = TriggerBuilder.newTrigger().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(Integer.parseInt("10")).repeatForever()).build();

            SchedulerFactory schFactory = new StdSchedulerFactory();
            Scheduler sch = schFactory.getScheduler();
            sch.start();
            sch.scheduleJob(job, trigger);

        }
        catch (SchedulerException e)
        {
            e.printStackTrace();
            System.out.println("Scheduler Error");
        }
    }
    public static class MyJob implements Job {
        @Override
        public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
            System.out.println("runnning job");
        }
    }
}
英文:

The log entry with NOT STARTED is misleading, as it is shown whenever a QuartzScheduler instance is created. It does not mean that the jobs are not running. It is written after the line Scheduler sch = schFactory.getScheduler(); is executed and the scheduler is started in the next line.

If I take your example and run it on my pc, it is working as designed:

public class Quartz {

    public static void main(String[] args) {
        try {

            JobDetail job = JobBuilder.newJob(MyJob.class).withIdentity("myJob").build();
            Trigger trigger = TriggerBuilder.newTrigger().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(Integer.parseInt("10")).repeatForever()).build();

            SchedulerFactory schFactory = new StdSchedulerFactory();
            Scheduler sch = schFactory.getScheduler();
            sch.start();
            sch.scheduleJob(job, trigger);

        }
        catch (SchedulerException e)
        {
            e.printStackTrace();
            System.out.println("Scheduler Error");
        }
    }
    public static class MyJob implements Job {
        @Override
        public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
            System.out.println("runnning job");
        }
    }
}

huangapple
  • 本文由 发表于 2020年4月8日 16:02:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/61095980.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定