gpt4 book ai didi

java - 如何在 Spring MVC 中设置 quartz 触发器的优先级

转载 作者:行者123 更新时间:2023-12-01 09:49:27 26 4
gpt4 key购买 nike

我使用带有 cron 表达式的 Quartz 调度程序来在我的 Java Spring MVC 应用程序中定期执行一些任务。在我的 root-context.xml 文件中,我有以下内容:

<!--Quartz Scheduler Beans   -->

<bean id="emailNotificationJob"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">

<property name="targetObject" ref="eventsService" />
<property name="targetMethod" value="sendEventEmailNotification" />
<property name="concurrent" value="false" /> <!-- this is the property to prevent concurrent execution -->
</bean>

<bean id="deleteWebContentsJob"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">

<property name="targetObject" ref="webContentDefinitionService" />
<property name="targetMethod" value="deleteWebContents" />
<property name="concurrent" value="false" />
</bean>


<bean id="saveStaticContentsJob"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">

<property name="targetObject" ref="webContentDefinitionService" />
<property name="targetMethod" value="saveStaticContents" />
<property name="concurrent" value="false" />
</bean>

<bean id="emailTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">

<property name="jobDetail" ref="emailNotificationJob" />
<property name="cronExpression" value="0 0/1 * 1/1 * ? *" />

</bean>

<bean id="deleteWebContentsTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">

<property name="jobDetail" ref="deleteWebContentsJob"/>
<property name="cronExpression" value="0 1 0 1/1 * ? *" />

</bean>


<bean id="staticContentsUploadTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">

<property name="jobDetail" ref="saveStaticContentsJob" />
<property name="cronExpression" value="0 0/1 * 1/1 * ? *" />

</bean>

<!-- Scheduler factory bean to glue together jobDetails and triggers to Configure Quartz Scheduler -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="emailNotificationJob" />
<ref bean="deleteWebContentsJob" />
<ref bean="saveStaticContentsJob" />
</list>
</property>

<property name="triggers">
<list>
<ref bean="emailTrigger" />
<ref bean="deleteWebContentsTrigger" />
<ref bean="staticContentsUploadTrigger" />
</list>
</property>
</bean>

<!-- Quartz Bean End -->

我在我的应用程序中使用 Quartz Scheduler 2.2.1

我想为各种触发器设置优先级。这里我有两个触发器,设置为以相同的时间间隔触发。我正在尝试将其中一个设置为优先级 1,另一个设置为优先级 2。有没有办法做到这一点。

最佳答案

CronTriggerFactoryBean 有一个名为 priority 的属性 (spring-context-support:4.2.4.RELEASE)。这又用于设置 CronTriggerImpl 的优先级,其具有 javadoc其中指出:

The priority of a Trigger acts as a tie breaker such that if two Triggers have the same scheduled fire time, then Quartz will do its best to give the one with the higher priority first access to a worker thread.

If not explicitly set, the default value is 5.

话又说回来,如果线程池中有足够的线程供两个进程使用,我不确定优先级是否会产生任何影响(取决于优先级是否也分配给实际的工作线程)。

关于java - 如何在 Spring MVC 中设置 quartz 触发器的优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37698305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com