I am using Spring boot with @EnableScheduling and @EnableAsync .
I have a method that annotates using @Scheduled . I have some more methods that are annotated using @Async .
Now I call these @Async methods in the @Async method and print the name of the current stream in async methods. I see that they all have the same stream name, in fact it is a stream that uses the @Scheduled method.
I do not see the execution of the asynchronous method. What is wrong here?
Here is my application boot class
@SpringBootApplication @EnableScheduling @EnableAsync public class ApplicationBoot { public static void main(String[] args) { SpringApplication.run(ApplicationBoot.class, args); } }
Here is my planner class
@Component public class TaskScheduler { private static final Logger logger = Logger.getLogger(TaskScheduler.class); @Scheduled(fixedDelay = 10000) public void ScheduledMethod() { methodOne(); methodTwo(); methodThree(); } @Async private void methodOne() { logger.info("Method one called by Thread : " + Thread.currentThread().getName() + " at " + new Date()); } @Async private void methodTwo() { logger.info("Method two called by Thread : " + Thread.currentThread().getName() + " at " + new Date()); } @Async private void methodThree() { logger.info("Method three called by Thread : " + Thread.currentThread().getName() + " at " + new Date()); } }
Output
Method one, called by thread: pool-1-thread-1 on Tue Apr 04 16:32:27 IST 2017
Method two is called thread: pool-1-thread-1 in Tue Apr 04 16:32:27 IST 2017
Method three is called thread: pool-1-thread-1 in Tue Apr 04 16:32:27 IST 2017
source share