1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
51
51
* detected via {@link #hasConcurrentResult()}.
52
52
*
53
53
* @author Rossen Stoyanchev
54
+ * @author Juergen Hoeller
54
55
* @since 3.2
55
56
* @see org.springframework.web.context.request.AsyncWebRequestInterceptor
56
57
* @see org.springframework.web.servlet.AsyncHandlerInterceptor
@@ -76,15 +77,13 @@ public final class WebAsyncManager {
76
77
77
78
private AsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor (this .getClass ().getSimpleName ());
78
79
79
- private Object concurrentResult = RESULT_NONE ;
80
+ private volatile Object concurrentResult = RESULT_NONE ;
80
81
81
- private Object [] concurrentResultContext ;
82
+ private volatile Object [] concurrentResultContext ;
82
83
83
- private final Map <Object , CallableProcessingInterceptor > callableInterceptors =
84
- new LinkedHashMap <>();
84
+ private final Map <Object , CallableProcessingInterceptor > callableInterceptors = new LinkedHashMap <>();
85
85
86
- private final Map <Object , DeferredResultProcessingInterceptor > deferredResultInterceptors =
87
- new LinkedHashMap <>();
86
+ private final Map <Object , DeferredResultProcessingInterceptor > deferredResultInterceptors = new LinkedHashMap <>();
88
87
89
88
90
89
/**
@@ -105,7 +104,7 @@ public final class WebAsyncManager {
105
104
* {@code true}.
106
105
* @param asyncWebRequest the web request to use
107
106
*/
108
- public void setAsyncWebRequest (final AsyncWebRequest asyncWebRequest ) {
107
+ public void setAsyncWebRequest (AsyncWebRequest asyncWebRequest ) {
109
108
Assert .notNull (asyncWebRequest , "AsyncWebRequest must not be null" );
110
109
this .asyncWebRequest = asyncWebRequest ;
111
110
this .asyncWebRequest .addCompletionHandler (() -> asyncWebRequest .removeAttribute (
@@ -130,7 +129,7 @@ public void setTaskExecutor(AsyncTaskExecutor taskExecutor) {
130
129
* processing of the concurrent result.
131
130
*/
132
131
public boolean isConcurrentHandlingStarted () {
133
- return (( this .asyncWebRequest != null ) && this .asyncWebRequest .isAsyncStarted ());
132
+ return (this .asyncWebRequest != null && this .asyncWebRequest .isAsyncStarted ());
134
133
}
135
134
136
135
/**
@@ -232,8 +231,10 @@ public void registerDeferredResultInterceptors(DeferredResultProcessingIntercept
232
231
* {@linkplain #getConcurrentResultContext() concurrentResultContext}.
233
232
*/
234
233
public void clearConcurrentResult () {
235
- this .concurrentResult = RESULT_NONE ;
236
- this .concurrentResultContext = null ;
234
+ synchronized (WebAsyncManager .this ) {
235
+ this .concurrentResult = RESULT_NONE ;
236
+ this .concurrentResultContext = null ;
237
+ }
237
238
}
238
239
239
240
/**
@@ -334,7 +335,7 @@ public void startCallableProcessing(final WebAsyncTask<?> webAsyncTask, Object..
334
335
335
336
private void setConcurrentResultAndDispatch (Object result ) {
336
337
synchronized (WebAsyncManager .this ) {
337
- if (hasConcurrentResult () ) {
338
+ if (this . concurrentResult != RESULT_NONE ) {
338
339
return ;
339
340
}
340
341
this .concurrentResult = result ;
@@ -349,7 +350,6 @@ private void setConcurrentResultAndDispatch(Object result) {
349
350
logger .debug ("Concurrent result value [" + this .concurrentResult +
350
351
"] - dispatching request to resume processing" );
351
352
}
352
-
353
353
this .asyncWebRequest .dispatch ();
354
354
}
355
355
@@ -425,8 +425,10 @@ public void startDeferredResultProcessing(
425
425
}
426
426
427
427
private void startAsyncProcessing (Object [] processingContext ) {
428
- clearConcurrentResult ();
429
- this .concurrentResultContext = processingContext ;
428
+ synchronized (WebAsyncManager .this ) {
429
+ this .concurrentResult = RESULT_NONE ;
430
+ this .concurrentResultContext = processingContext ;
431
+ }
430
432
this .asyncWebRequest .startAsync ();
431
433
432
434
if (logger .isDebugEnabled ()) {
0 commit comments