更改Quartz JobDetails的名称

发布于 2025-02-07 19:01:57 字数 1745 浏览 3 评论 0 原文

我有一个石英作业:

<bean id="exportResult" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
  <property name="jobClass" value="com.al6.integration.quartz.JobLauncherDetails"/>
  <property name="name" value="TestJob"/>
  <property name="durability" value="false"/>
  <property name="requestsRecovery" value ="true"/>
  <property name="jobDataAsMap">
      <map>
      <entry key="jobName" value="TestJob" />
    </map>
  </property>
</bean>

如果我在此作业并行两次,我有一个错误:

org.quartz.ObjectAlreadyExistSexception:无法存储作业...因为这个识别已经存在。

因此,我想动态更新作业的名称:

private JobDetail exportResult;
    
private Trigger trigger;

...

String uniqueID = "TestJob" + UUID.randomUUID().toString();
exportResult.setName(uniqueID);
trigger.setJobName(uniqueID);
scheduler.scheduleJob( exportResult, trigger);

它似乎在远程调试中起作用,但是当我尝试使用Maven编译时,它找不到setName方法:

cannot find symbol
[ERROR] symbol:   method setName(java.lang.String)
[ERROR] location: variable exportResult of type org.quartz.JobDetail
cannot find symbol
[ERROR] symbol:   method setJobName(java.lang.String)
[ERROR] location: variable trigger of type org.quartz.Trigger

似乎在QUART-之前存在该方法“ setName”调度程序版本&lt; 2.0.0:

https://javadoc.io/doc.io/doc/doc/doc/doc/org.quartz-scheduler/quartz/1.8.6/org/org/quartz/jobdetail.html-.html.html.html.html。

那我该如何更改名称?

I have a quartz job :

<bean id="exportResult" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
  <property name="jobClass" value="com.al6.integration.quartz.JobLauncherDetails"/>
  <property name="name" value="TestJob"/>
  <property name="durability" value="false"/>
  <property name="requestsRecovery" value ="true"/>
  <property name="jobDataAsMap">
      <map>
      <entry key="jobName" value="TestJob" />
    </map>
  </property>
</bean>

If I launch two times in parallel this job, I had this error :

org.quartz.ObjectAlreadyExistsException: Unable to store Job...because one already exists with this identification.

So I want to update the Name of the job dynamically :

private JobDetail exportResult;
    
private Trigger trigger;

...

String uniqueID = "TestJob" + UUID.randomUUID().toString();
exportResult.setName(uniqueID);
trigger.setJobName(uniqueID);
scheduler.scheduleJob( exportResult, trigger);

It seem to work in remote debug, but when I try to compile with maven, it can't find the setName method :

cannot find symbol
[ERROR] symbol:   method setName(java.lang.String)
[ERROR] location: variable exportResult of type org.quartz.JobDetail
cannot find symbol
[ERROR] symbol:   method setJobName(java.lang.String)
[ERROR] location: variable trigger of type org.quartz.Trigger

It seems that the method "setName" existed before quart-scheduler version < 2.0.0 :

https://javadoc.io/doc/org.quartz-scheduler/quartz/2.0.0/org/quartz/JobDetail.html

https://javadoc.io/doc/org.quartz-scheduler/quartz/1.8.6/org/quartz/JobDetail.html

How can I change the name then ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攀登最高峰 2025-02-14 19:01:57

名称和组是只读的属性,因为它们是JobKey属性(JobDetail.getKey() - &gt; JobKey)中的最终字段,

我建议您动态创建作业,因此您可以保证生成独特的名称。工厂模式可能很有用。

Name and Group are read-only properties, as they are final fields in the JobKey property (JobDetail.getKey() --> JobKey)

I would suggest you to create the Jobs dynamically, so you can guarantee to generate unique names. The Factory pattern could be useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文