Platform-http do not spawn useless threads #1354
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The previous implementation was creating 2 threads per request, the first one, created by spring framework via AsyncExecutionInterceptor, and the second one with
CompletableFuture.runAsync
.This PR avoids the creation of the 2nd thread, this way, the behavior is like plain Spring Boot
@Async
. And the Apache Camel thread pool can be controlled viaWhile improving this behavior I faced an issue with the return object of the service method, in particular, as you can see from https://github.com/apache/camel-spring-boot/compare/main...Croway:suboptimal-thread-usage?expand=1#diff-7844a79d0aab67af46e8f0538438aa37f3c8b8afb04072724cc78fcf8acb17f5R84 the method still returns CompletableFuture, though I am not doing a runAsync or supplyAsync (the service method is already running asynchronously) and the return is
CompletableFuture.completedFuture(null)
.I tried using
void
instead ofCompletableFuture
, but I was getting the following errorThe request object has been recycled and is no longer associated with this facade
when accessing the HttpServletRequest Object, I do not fully understand this behavior, maybe Spring expects a completable future.