1

I am using spring 4.0.2 The @scheduled annotation is not working properly in the given interval. This is my code

@Scheduled(initialDelay=60*1000, fixedRate=60*1000) //60secs
    private void method() {
        System.out.println("Scheduled Task Running @"+new Date());
    }

And this is my output

Scheduled Task Running @Thu Sep 21 12:00:51 IST 2017
Scheduled Task Running @Thu Sep 21 12:00:57 IST 2017
Scheduled Task Running @Thu Sep 21 12:01:51 IST 2017
Scheduled Task Running @Thu Sep 21 12:01:57 IST 2017
Scheduled Task Running @Thu Sep 21 12:02:51 IST 2017
Scheduled Task Running @Thu Sep 21 12:02:57 IST 2017

My requirement is for every one minute the method should be invoked. Its working, but after 6 secs of method invocation it's invoking the method again. So the method was invoked twice in a minute. Can any one tell why its behaving like this? How can I solve this?

Thanks,

Arulmurugan
  • 509
  • 1
  • 5
  • 6
  • 1
    I just tested it (spring 4.3.9) and it works every 60 secs. Are you sure that you do not have the same scheduled method twice in your code? – pleft Sep 21 '17 at 06:59
  • Your code works in my system also . . – Ajit Soman Sep 21 '17 at 07:12
  • I am sure. I didn't have the method twice in my code. my spring version is 4.0.2. I will check with 4.3.9 – Arulmurugan Sep 21 '17 at 08:11
  • You have both a `ContextLoaderListener` and a `DispatcherServlet`. Both have a `` or `@ComponentScan` scanning the same packages. Leading to initializing all your beans twice... – M. Deinum Sep 21 '17 at 08:44

0 Answers0