在java中使用quartz_如何在Java中使用Quartz Scheduler框架运行cron作业?

我在Java中使用Quartz Scheduler来运行cron作业 . 这是我第一次使用这个框架来运行cron作业,所以我有些困惑 .

我正在关注这个tutorial以更好地理解如何使用Quartz框架 .

我想每周和每个月都运行 JobA 所以我从基本的例子开始 -

这是我到目前为止的例子 .

public class JobA implements Job {

@Override

public void execute(JobExecutionContext context)

throws JobExecutionException {

System.out.println("Job A is runing");

// print whether it is week or month

}

}

下面是我的CronTriggerExample,它安排要运行的作业

public class CronTriggerExample {

public static void main(String[] args) throws Exception {

JobKey jobKeyA = new JobKey("jobA", "group1");

JobDetail jobA = JobBuilder.newJob(JobA.class).withIdentity(jobKeyA)

.build();

Trigger trigger1 = TriggerBuilder

.newTrigger()

.withIdentity("dummyTriggerName1", "group1")

.withSchedule(CronScheduleBuilder.cronSchedule("5 8 * * 6 ?"))

.build();

Scheduler scheduler = new StdSchedulerFactory().getScheduler();

scheduler.start();

scheduler.scheduleJob(jobA, trigger1);

}

}

Problem Statement:-

我不知道如何使用上面的代码每周和每月运行JobA . 在我的案例中,一周和一个月的cron标签条目是什么?我不想在晚上8点到凌晨5点之间运行任何工作,任何随机日都可以 .

如果JobA每周都在运行,那么它应该打印出 one-week 和 report_week . 但是如果JobA每个月都在运行,那么它应该打印 one-month 和 report_one_month 所以接下来的问题是 - 有什么办法,我们可以在尝试运行时将参数传递给JobA吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值