I have a long running service method which I'm starting with a rest call from the controller.
Service:
@Service
public class TestServiceImpl implements TestService {
@Override
public void doSomething() {
System.out.println("1: " + DateTime.now());
runLongTask();
System.out.println("2: " + DateTime.now());
}
@Async
private runLongTask() {
System.out.println("Test");
Thread.sleep(10000);
System.out.println("3: "+ DateTime.now());
}
}
In my Application.java I have
private int poolSize = 10;
private int queueCapacity = 10;
@Bean(name="taskExecutor")
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setMaxPoolSize(this.poolSize);
taskExecutor.setQueueCapacity(this.queueCapacity);
taskExecutor.afterPropertiesSet();
return new ThreadPoolTaskExecutor();
}
And of course I have the @EnableAsync Annotation at my Application.java class
So I would Expect that the output is something like that:
1: 2015-10-23 11:20:00
2: 2015-10-23 11:20:01
Test
3: 2015-10-23 11:20:11