I have a spring application which has two classes annotated with @Component, in each class, I have a method annotated with @Scheduled, that means I want to run those methods at the fixed interval like this :
This is First Component which has a readFirstComponent() method, this methos read something from somewhere and it takes awhile to carries out, @Component public class FirstComp {
@Scheduled(fixedRate = 20000 )
public void readFirstComponent() {
// body
}
//other methods }
Second component almost doing the same as First Component does,
@Component
public class SecondComp {
@Scheduled(fixedRate = 20000 )
public void readSecondComponent() {
// body
}
//other methods }
I have a runner class to start the application
@SpringBootApplication
@EnableScheduling
@ImportResource("classpath:spring/Spring-AutoScan.xml")
public class Application {
public static void main(final String args[]) {
SpringApplication.run(Application.class);
}
}
When I start the application FirtComp is starting and readFirstComponent() carrying out after nearly 14s coming to the end THEN readSecondComponent() from SecondComp is starting, and so on, My problem is that I want to start both methods concurrently, please help me to fix this problem