Skip to content

Commit 2553fb8

Browse files
committed
Apply ListenableFuture support to AspectJ
Prior to this commit, only @async annotated methods with proxy style had an explicit support for ListenableFuture. This commit brings that support to AspectJ as well. Issue: SPR-12092
1 parent bccb3bb commit 2553fb8

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

spring-aspects/src/main/java/org/springframework/scheduling/aspectj/AbstractAsyncExecutionAspect.aj

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import java.util.concurrent.Future;
2323
import org.aspectj.lang.reflect.MethodSignature;
2424

2525
import org.springframework.aop.interceptor.AsyncExecutionAspectSupport;
26+
import org.springframework.core.task.AsyncListenableTaskExecutor;
2627
import org.springframework.core.task.AsyncTaskExecutor;
28+
import org.springframework.util.concurrent.ListenableFuture;
2729

2830
/**
2931
* Abstract aspect that routes selected methods asynchronously.
@@ -75,11 +77,16 @@ public abstract aspect AbstractAsyncExecutionAspect extends AsyncExecutionAspect
7577
}
7678
return null;
7779
}};
78-
Future<?> result = executor.submit(callable);
79-
if (Future.class.isAssignableFrom(methodSignature.getReturnType())) {
80-
return result;
80+
81+
Class<?> returnType = methodSignature.getReturnType();
82+
if (ListenableFuture.class.isAssignableFrom(returnType)) {
83+
return ((AsyncListenableTaskExecutor) executor).submitListenable(callable);
84+
}
85+
else if (Future.class.isAssignableFrom(returnType)) {
86+
return executor.submit(callable);
8187
}
8288
else {
89+
executor.submit(callable);
8390
return null;
8491
}
8592
}

0 commit comments

Comments
 (0)