Prevent duplication in Repeating Annotations

柔情痞子 提交于 2019-12-25 01:19:36

问题


Repeating Annotations as @Scheduled allow multiple annotations

But it also allows duplicated values in different annotation which can cause unexpected results

Simple example using Scheduled with duplicated fixedRate values:

private static final long TIME = 1000 * 60 * 1L; // 1 minute
private static final long TIME2 = 1000 * 60 * 1L; // 1 minute
@Scheduled(fixedRate = TIME)
@Scheduled(fixedRate = TIME2)
public synchronized void refresh() {

It will execute twice per minute the schedule task instead of once

Is there a a way to avoid using duplicated value in repeated annotation?

Is there any rule (or can I suggest new rule) in sonar or other static code analysis tool?

来源:https://stackoverflow.com/questions/54061630/prevent-duplication-in-repeating-annotations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!