问题
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