Browse Source

Add trySet method to DeferredResult

The method absorbs any potential StaleAsyncWebRequestException and
returns false instead.

Issue: SPR-8517
pull/77/head
Rossen Stoyanchev 14 years ago
parent
commit
c57d4e2386
  1. 16
      spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java
  2. 9
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

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

@ -103,6 +103,22 @@ public final class DeferredResult { @@ -103,6 +103,22 @@ public final class DeferredResult {
}
}
/**
* A variant of {@link #set(Object)} that absorbs a potential, resulting
* {@link StaleAsyncWebRequestException}.
* @return {@code false} if the outcome was a {@code StaleAsyncWebRequestException}
*/
public boolean trySet(Object result) throws StaleAsyncWebRequestException {
try {
set(result);
return true;
}
catch (StaleAsyncWebRequestException ex) {
// absorb
}
return false;
}
/**
* Invoked to complete async processing when a timeout occurs before
* {@link #set(Object)} is called. Or if {@link #set(Object)} is already in

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

@ -388,10 +388,11 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i @@ -388,10 +388,11 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i
}
/**
* Set an AsyncTaskExecutor to use when a controller method returns a Callable.
* <p>The default is a {@link SimpleAsyncTaskExecutor}
*
* TODO... need a better default
* Set the AsyncTaskExecutor to use when a controller method returns a
* {@code Callable}.
* <p>The default instance type is a {@link SimpleAsyncTaskExecutor}.
* It's recommended to change that default in production as the simple
* executor does not re-use threads.
*/
public void setAsyncTaskExecutor(AsyncTaskExecutor taskExecutor) {
this.taskExecutor = taskExecutor;

Loading…
Cancel
Save