栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

CronSequenceGenerator的解决方法一个月的最后一天?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CronSequenceGenerator的解决方法一个月的最后一天?

此功能不是标准cron表达式语法。因此,Spring可能永远不会实现它。看代码,我看不到任何
外科 解决方案的扩展

CronSequenceGenerator
。那么,为什么不使用Quartz却是一个特殊功能呢?

根据您的确切需求,您可以实现自己的Trigger。就像是:

import java.util.Date;import org.joda.time.LocalDate;import org.joda.time.LocalTime;import org.springframework.scheduling.Trigger;import org.springframework.scheduling.TriggerContext;public class LastDayOfMonthTrigger implements Trigger {    private final LocalTime time;    public LastDayOfMonthTrigger(LocalTime time) {        this.time = time;    }    @Override    public Date nextExecutionTime(TriggerContext ctx) {        Date last = ctx.lastScheduledExecutionTime();        LocalDate date = last == null ? new LocalDate() : new LocalDate(last).plusDays(1);        LocalDate lastDay = date.dayOfMonth().withMaximumValue();        return lastDay.toDateTime(time).toDate();    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/382795.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号