Affects: 5.1.7
Code to reproduce issue:
@SpringBootApplication
@EnableAsync
@EnableScheduling
public class SpringAsyncTestApplication
{
private static final Logger LOG = LoggerFactory.getLogger(SpringAsyncTestApplication.class);
public static void main(String[] args)
{
SpringApplication.run(SpringAsyncTestApplication.class, args);
}
@Async
@Scheduled(fixedDelay = 1000)
public void test1() throws InterruptedException
{
LOG.info(String.format("Test 1 start: %s", Thread.currentThread().getName()));
Thread.sleep(1100);
LOG.info(String.format("Test 1 end: %s", Thread.currentThread().getName()));
}
@Async
@Scheduled(fixedDelay = 1000)
public void test2() throws InterruptedException
{
LOG.info(String.format("Test 2 start: %s", Thread.currentThread().getName()));
Thread.sleep(1100);
LOG.info(String.format("Test 2 end: %s", Thread.currentThread().getName()));
}
}
Expected result: Each test1() method is started 1 second after previous test1() method ends. Each test2() method is started 1 second after previous test2() method ends. test1() and test2() methods are running in parallel;
Actual result: Each test1() method is started before previous test1() method ends. Each test2() method is started before previous test2() method ends.
Actual output:
2019-06-07 18:46:32.651 INFO 26930 --- [ task-1] c.g.ne0sight.SpringAsyncTestApplication : Test 1 start: task-1
2019-06-07 18:46:32.651 INFO 26930 --- [ task-2] c.g.ne0sight.SpringAsyncTestApplication : Test 2 start: task-2
2019-06-07 18:46:33.647 INFO 26930 --- [ task-3] c.g.ne0sight.SpringAsyncTestApplication : Test 1 start: task-3
2019-06-07 18:46:33.648 INFO 26930 --- [ task-4] c.g.ne0sight.SpringAsyncTestApplication : Test 2 start: task-4
2019-06-07 18:46:33.751 INFO 26930 --- [ task-2] c.g.ne0sight.SpringAsyncTestApplication : Test 2 end: task-2
2019-06-07 18:46:33.751 INFO 26930 --- [ task-1] c.g.ne0sight.SpringAsyncTestApplication : Test 1 end: task-1
2019-06-07 18:46:34.647 INFO 26930 --- [ task-5] c.g.ne0sight.SpringAsyncTestApplication : Test 1 start: task-5
2019-06-07 18:46:34.648 INFO 26930 --- [ task-6] c.g.ne0sight.SpringAsyncTestApplication : Test 2 start: task-6
2019-06-07 18:46:34.747 INFO 26930 --- [ task-3] c.g.ne0sight.SpringAsyncTestApplication : Test 1 end: task-3
2019-06-07 18:46:34.749 INFO 26930 --- [ task-4] c.g.ne0sight.SpringAsyncTestApplication : Test 2 end: task-4
2019-06-07 18:46:35.648 INFO 26930 --- [ task-7] c.g.ne0sight.SpringAsyncTestApplication : Test 1 start: task-7
2019-06-07 18:46:35.649 INFO 26930 --- [ task-8] c.g.ne0sight.SpringAsyncTestApplication : Test 2 start: task-8
2019-06-07 18:46:35.748 INFO 26930 --- [ task-5] c.g.ne0sight.SpringAsyncTestApplication : Test 1 end: task-5
2019-06-07 18:46:35.749 INFO 26930 --- [ task-6] c.g.ne0sight.SpringAsyncTestApplication : Test 2 end: task-6
2019-06-07 18:46:36.648 INFO 26930 --- [ task-2] c.g.ne0sight.SpringAsyncTestApplication : Test 1 start: task-2
2019-06-07 18:46:36.649 INFO 26930 --- [ task-1] c.g.ne0sight.SpringAsyncTestApplication : Test 2 start: task-1
2019-06-07 18:46:36.748 INFO 26930 --- [ task-7] c.g.ne0sight.SpringAsyncTestApplication : Test 1 end: task-7
2019-06-07 18:46:36.749 INFO 26930 --- [ task-8] c.g.ne0sight.SpringAsyncTestApplication : Test 2 end: task-8
Comment From: edsenabr
Hi, @nE0sIghT , did you manage to solve this ?
Comment From: nE0sIghT
I wrongly used task Scheduller, as I remember.