Good morning everybody, First of all, I have to say that How to go from XML Spring scheduling configuration to annotation/code configuration? topic could answer my question but I don't know Spring working enough to understand it : According to https://spring.io/guides/gs/scheduling-tasks/ tuto, I have main Application class and ScheduledTasks class which contains N methods that have to be launched independently (task1 must run in parallel with task2 but 2 task1 must not run in the same time).
Currently, all methods are executed sequentially and I'm asking how to configure that (), if possible only with annotations, withous xml file ? - Have I to put Async annotation? If so, where to put @EnableAsync : on the Application class or one the ScheduledTasks class ? - If I have to create xml file, how to link it with my Java classes and tell to main() to take it into account ? - How to reference in a xml file, a bean which have been created with annotation ? - Can't I just add new class with @Configuration to define a ScheduledThreadPoolExecutor with N size ? - Can/should I have to put this configuration into Application class because it use @SpringBootApplication which include @Configuration tags ?
Has you can see, Spring and SpringBoot are quite confusing for me because I don't used it a lot for the moment and don't know how to mix annotations and xml files.
Thanks a lot for your attention !
Edit1 : According to http://www.concretepage.com/spring/example_threadpooltaskexecutor_spring, I created new Conf without bean creation because my ScheduledTasks class is already "beanify" by using @Component if I understood well. It does not do what I want : it allow all tasks to execute asynchronously (task1 & task2 and task1 & task1) even if I specify fixedDelay instead of fixedRate (@Async used). In the same mind, even with fixedRate instead of fixedDelay and without @Async, task1 are not run parallely (that's not what I want but it's just to understand)
Edit2 : I rollback my work and do not use AsyncConfigurer because this is not async that I want so I added following code to my Application class (or in a new separate @Configuration class (anywhere in fact)) :
@Bean
public TaskScheduler poolScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setThreadNamePrefix("poolScheduler");
scheduler.setPoolSize(2);
return scheduler;
}
and it works !!!! But I don't understand why, this seems to be magic and I hate this in computer science !!! --> how does Spring know that it has to use this new bean specifically for my scheduler ? The bean is just created, not associated to my scheduler, no ?