我有一个石英作业:
<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 ?
发布评论
评论(1)
名称和组是只读的属性,因为它们是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.