diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java index 70e89d1bcea..9510ea144b8 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.context.request.async; import java.util.PriorityQueue; @@ -20,6 +21,7 @@ import java.util.concurrent.Callable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.util.Assert; import org.springframework.web.context.request.NativeWebRequest; @@ -63,9 +65,9 @@ public class DeferredResult { private DeferredResultHandler resultHandler; - private Object result = RESULT_NONE; + private volatile Object result = RESULT_NONE; - private boolean expired; + private volatile boolean expired; /** @@ -94,17 +96,17 @@ public class DeferredResult { this.timeout = timeout; } + /** * Return {@code true} if this DeferredResult is no longer usable either * because it was previously set or because the underlying request expired. - *

- * The result may have been set with a call to {@link #setResult(Object)}, + *

The result may have been set with a call to {@link #setResult(Object)}, * or {@link #setErrorResult(Object)}, or as a result of a timeout, if a * timeout result was provided to the constructor. The request may also * expire due to a timeout or network error. */ public final boolean isSetOrExpired() { - return ((this.result != RESULT_NONE) || this.expired); + return (this.result != RESULT_NONE || this.expired); } /** @@ -145,12 +147,12 @@ public class DeferredResult { Assert.notNull(resultHandler, "DeferredResultHandler is required"); synchronized (this) { this.resultHandler = resultHandler; - if ((this.result != RESULT_NONE) && (!this.expired)) { + if (this.result != RESULT_NONE && !this.expired) { try { this.resultHandler.handleResult(this.result); } - catch (Throwable t) { - logger.trace("DeferredResult not handled", t); + catch (Throwable ex) { + logger.trace("DeferredResult not handled", ex); } } } @@ -194,9 +196,9 @@ public class DeferredResult { return setResultInternal(result); } + final DeferredResultProcessingInterceptor getInterceptor() { return new DeferredResultProcessingInterceptorAdapter() { - @Override public boolean handleTimeout(NativeWebRequest request, DeferredResult deferredResult) { if (timeoutCallback != null) { @@ -207,7 +209,6 @@ public class DeferredResult { } return true; } - @Override public void afterCompletion(NativeWebRequest request, DeferredResult deferredResult) { synchronized (DeferredResult.this) {