gpt4 book ai didi

java - 获取@Scheduled内的fixedDelay值

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:04 25 4
gpt4 key购买 nike

是否可以在正在执行的方法内获取fixedDelay的值?

是否存在这样的事情:

@Scheduled(fixedDelay = 86400000) //one day
public void sendEmails() {
System.out.println(TaskExecutor.getCurrentFixedDelay()); // (would print 86400000)
}

最佳答案

    public class AnnotationParameter {

@Scheduled(fixedDelay = 86400000) //one day
public void sendEmails() throws NoSuchMethodException
{
Method method = AnnotationParameter.class.getDeclaredMethod
("sendEmails");
Scheduled annotation = method.getAnnotation(Scheduled.class);
long fixedDelay = annotation.fixedDelay();
System.out.println(fixedDelay); // (would print 86400000)
}

public static void main(String[] args) throws NoSuchMethodException
{
new AnnotationParameter().sendEmails();
}
}

关于java - 获取@Scheduled内的fixedDelay值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31253115/

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