【发布时间】:2014-09-29 16:53:41
【问题描述】:
我正在使用 Spring 集成 3.0.0。我们需要在运行时动态更改轮询间隔。 我遵循了以下方法,设置了一个带有轮询器的入站适配器,每 5 分钟轮询一次。我使用 Cron 是因为我们希望拥有高级调度能力(即我们可以将轮询器更改为仅在一天中的特定时间进行轮询)
在运行时,我获得了对适配器的引用,停止了适配器,使用新表达式创建了一个新的 crontrigger,将新触发器设置为适配器并启动了适配器。
<file:inbound-channel-adapter id="fileInboundAdapter"
channel="filesIn" directory="C:\\TEMP\\input\\">
<int:poller id="poller" cron="0 0/5 * * * *"
error-channel="errorChannel" max-messages-per-poll="1" />
</file:inbound-channel-adapter>
SourcePollingChannelAdapter sourcePollingChannelAdapter = (SourcePollingChannelAdapter) context
.getBean("fileInboundAdapter");
CronTrigger cronTrigger = new CronTrigger("0 0/10 * * * *");
sourcePollingChannelAdapter.stop();
sourcePollingChannelAdapter.setTrigger(cronTrigger);
sourcePollingChannelAdapter.start();
该方法运行良好。
但在论坛中,与同一问题相关的主题之一(http://forum.spring.io/forum/spring-projects/integration/113138-problems-while-trying-to-modify-polling-rate-on-runtime),Spring 开发人员建议不要在运行时更改触发器引用,而是创建自己的触发器实现。
- 谁能解释一下为什么我们不应该在运行时更改触发器引用?
- 上述方法是否存在缺陷
- 我想让新的 Cron 立即生效。即取消当前计划任务并使用新的 Cron 表达式计划一个新任务。是否可以使用自定义触发器方法?
感谢您的帮助。
谢谢,
【问题讨论】: