无法使用不同作业名称和组运行相同的类,在同一时间运行。

huangapple 未分类评论61阅读模式
标题翻译

not able to run same class with diff job name and group, run at same time

问题

我正在开发一个石英调度器。
我创建了一个实现了Job接口的类(com.test.job.MyClass)。
MyClass包含一些动态值,这些值在调度时传递给DataMap。根据datamap的值,我需要通过传递这个datamap的值来调用rest API。

因此在我的数据库中,我定义了具有className、jobName、groupName和operationValue的作业。我在数据库中定义了多个条目,其中包含

比如作业1是

jobClassName=com.test.job.MyClass
jobName=TEST1
groupName=group
operationValue=ADD

比如作业2是

jobClassName=com.test.job.MyClass
jobName=TEST2
groupName=group
operationValue=ADD

我尝试安排这2个具有相同Cron表达式的作业。但只有TEST1作业在执行。TEST2没有执行。即使jobName不同

Scheduler scheduler=scheduleFactory.getScheduler();
try {
    Class<? extends Job> jobClassName=(Class<? extends Job>)Class.forName(className);
    JobDetail jobDetails=JobBuilder.newJob(jobClassName).withIdentity(jobName,groupName).build();
    putIntoDataMap(job,jobDetails.getJobDataMap(),user);
    CronTrigger trigger=newTrigger().withIdentity(jobName,groupName)
        .withSchedule(cronSchedule(cronExpression).inTimeZone("Asia/Kolkata")).build();

    scheduler.scheduleJob(jobDetails,trigger);
} catch(SchedulerException|ClassNotFoundException ex) {
    throw new CredityRuntimeException(CredityErrorCodes.INVALID_TRIGGER.name(),ex);
}

在实现的类中,我可以看到ADD操作,这意味着只有TEST1被运行。我期望两个都应该运行。

public class MyClass implements Job {

@Override
public void execute(JobExecutionContext context) throws JobExecutionException
{
    .....
    String operationValue=jobDataMap.get("Operation");
}

}

英文翻译

I am working on a quartz scheduler.
I have created a class(com.test.job.MyClass) that implements Job
MyClass contains some dynamic values which pass in DataMap while scheduling. based on datamap value, i need to invoke the rest API by passing this data map value.

So in my DB, I defined job having className, jobName, groupName and operationValue. I have defined multiple entries in DB having

Like JOB-1 is

jobClassName= com.test.job.MyClass
jobName=TEST1
groupName =group
operationValue =ADD

Like JOB-2 is

jobClassName= com.test.job.MyClass
jobName=TEST2
groupName =group
operationValue =ADD

I am trying to schedule these 2 jobs having same Cron expression. but only the TEST1 job is executing. Test2 is not. even the jobName is different

Scheduler scheduler = scheduleFactory.getScheduler();
		try {
			Class&lt;? extends Job&gt; jobClassName = (Class&lt;? extends Job&gt;) Class.forName(className);
			JobDetail jobDetails = JobBuilder.newJob(jobClassName).withIdentity(jobName, groupName).build();
			putIntoDataMap(job, jobDetails.getJobDataMap(), user);
			CronTrigger trigger = newTrigger().withIdentity(jobName, groupName)
					.withSchedule(cronSchedule(cronExpression).inTimeZone(&quot;Asia/Kolkata&quot;)).build();

			scheduler.scheduleJob(jobDetails, trigger);
		} catch (SchedulerException | ClassNotFoundException ex) {
			throw new CredityRuntimeException(CredityErrorCodes.INVALID_TRIGGER.name(), ex);
		}

in the implemented class, I can see ADD operation, so it means only TEST1 was run. I expect both should run.

public class MyClass implements Job {

@Override
	public void execute(JobExecutionContext context) throws JobExecutionException 
    {
        .....
         String operationValue=jobDataMap.get(&quot;Operation&quot;);
    }
}

答案1

得分: 0

非常奇怪。您可能想要使用QuartzDesk(在这里我有偏见),或者其他一些替代的Quartz管理GUI工具来执行以下操作:

(1)连接到您的Quartz实例并检查注册的作业和触发器。在您的情况下,您应该能够看到两个作业TEST1和TEST2。

(2)尝试手动执行已注册的作业,以查看是否可以调用您的作业。

注意:免费的QuartzDesk Lite版应该完全足够,并能帮助您快速识别问题所在。

需要注意的一件事是作业的持久性标志。非持久的Quartz作业会在将来没有预期触发作业的相关触发器时被Quartz自动丢弃。由于您没有提供TEST1和TEST2的cron表达式,因此在构建作业详细信息时,您可能需要调用storeDurably...(此处省略)

英文翻译

Very strange. You may want to use QuartzDesk (I am biased here) or some other alternative Quartz management GUI tool to:

(1) connect to your Quartz instance and check the registered jobs and triggers. In your case, you should see two jobs TEST1 and TEST2.

(2) try to manually execute the registered jobs to see if your jobs can be invoked.

Note: The free QuartzDesk Lite Edition should be entirely sufficient and help you quickly identify the issue.

One thing to be aware of is the job durability flag. Non-durable Quartz jobs are automatically discarded by Quartz when there are no associated triggers that are expected to fire the job in the future. You did not include your cron expressions for TEST1 and TEST2 so you may want to call storeDurably when building your job details just in case...

huangapple
  • 本文由 发表于 2020年5月31日 02:59:19
  • 转载请务必保留本文链接:https://java.coder-hub.com/62107346.html
匿名

发表评论

匿名网友

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

确定