【问题标题】:Timer boundary event task定时器边界事件任务
【发布时间】:2021-03-18 08:45:22
【问题描述】:
我有一个任务,如果计划截止日期临近并且还剩 30 天,您需要发送通知,并在截止日期剩余时间前 5 天发送通知。我现在搜索了很多,现在我找不到哪个元素以及如何做的答案。我想使用 Timer 事件,但是如果我在 cron 的帮助下这样做,那么如果发送通知不相关,那么如何理解你需要离开任务并且每次都不再运行该方案
【问题讨论】:
标签:
java
bpmn
business-process-management
camunda-modeler
【解决方案1】:
Timer 类一般被 Executors 框架提供的调度执行器服务所淘汰。
安排一个经常运行的任务,看看是否临近截止日期。
if( thirtyDayNoticeNotYetSent ) {
LocalDate then = … retrieve date due … ;
LocalDate today = LocalDate.now( ZoneId.of( "America/Edmonton" ) ) ;
long daysUntil = ChronoUnit.DAYS.between( today , then ) ;
if( daysUntil < 30 ) { send notification … }
}
同样,搜索尚未收到 5 天通知的工作,并计算经过的天数。如果不到五岁,请发送通知并记录该事实。
Scheduled executor 服务已在 Stack Overflow 上多次介绍。因此,搜索以了解更多信息。