Skip to content

Commit c57d4e2

Browse files
committed
Add trySet method to DeferredResult
The method absorbs any potential StaleAsyncWebRequestException and returns false instead. Issue: SPR-8517
1 parent 897f6d6 commit c57d4e2

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ public void set(Object result) throws StaleAsyncWebRequestException {
103103
}
104104
}
105105

106+
/**
107+
* A variant of {@link #set(Object)} that absorbs a potential, resulting
108+
* {@link StaleAsyncWebRequestException}.
109+
* @return {@code false} if the outcome was a {@code StaleAsyncWebRequestException}
110+
*/
111+
public boolean trySet(Object result) throws StaleAsyncWebRequestException {
112+
try {
113+
set(result);
114+
return true;
115+
}
116+
catch (StaleAsyncWebRequestException ex) {
117+
// absorb
118+
}
119+
return false;
120+
}
121+
106122
/**
107123
* Invoked to complete async processing when a timeout occurs before
108124
* {@link #set(Object)} is called. Or if {@link #set(Object)} is already in

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,11 @@ public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect
388388
}
389389

390390
/**
391-
* Set an AsyncTaskExecutor to use when a controller method returns a Callable.
392-
* <p>The default is a {@link SimpleAsyncTaskExecutor}
393-
*
394-
* TODO... need a better default
391+
* Set the AsyncTaskExecutor to use when a controller method returns a
392+
* {@code Callable}.
393+
* <p>The default instance type is a {@link SimpleAsyncTaskExecutor}.
394+
* It's recommended to change that default in production as the simple
395+
* executor does not re-use threads.
395396
*/
396397
public void setAsyncTaskExecutor(AsyncTaskExecutor taskExecutor) {
397398
this.taskExecutor = taskExecutor;

0 commit comments

Comments
 (0)