I'm trying to implement concurrent method invocation in my Service class.
I've some methods annotated as @Async in my service class and I'm trying to call all these methods concurrently. But the methods are executing sequentially.
This is my service class(dummy):
@Service public class TestService {
public SomeDataType getSOmeDataType() {
try {
List<DataType> a = retrieveDataA().get();
List<DataType> b = retrieveDataB().get();
List<DataType> c = retrieveDataC().get();
List<DataType> d = retrieveDataD().get();
List<DataType> e = retrieveDataE().get();
}
catch (InterruptedException e) {
e.printStackTrace();
}
catch (ExecutionException e) {
e.printStackTrace();
}
return referralDetailsReferenceData;
}
@Async
private Future<List<DataType>> retrieveDataA() {
//method logic
}
@Async
private Future<List<DataType>> retrieveDataB() {
//method logic
}
@Async
private Future<List<DataType>> retrieveDataC() {
//method logic
}
@Async
private Future<List<DataType>> retrieveDataD() {
//method logic
}
@Async
private Future<List<DataType>> retrieveDataE() {
//method logic
}
This is my spring config:
<bean id="executorService" class="java.util.concurrent.Executors" factory-method="newFixedThreadPool">
<constructor-arg value="10" />
</bean>
<task:executor id="threadPoolTaskExecutor" pool-size="10" />
<task:annotation-driven executor="executorService" />
When "getSomeDataType" is executed the methods are invoked sequentially.
I'm new to @Async and concurrent execution in Spring, so I'm sure I'm doing something silly. But I'm not able to figure it out.
Any suggestions is highly appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…