wu-sheng commented on a change in pull request #738: Concurrency conflicts in
Spring plugin #735
URL:
https://github.com/apache/incubator-skywalking/pull/738#discussion_r160863648
##########
File path:
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/EnhanceRequireObjectCache.java
##########
@@ -18,25 +18,26 @@
package org.apache.skywalking.apm.plugin.spring.mvc.commons;
-import java.lang.reflect.Method;
-import javax.servlet.http.HttpServletResponse;
import org.springframework.web.context.request.NativeWebRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.lang.reflect.Method;
+
public class EnhanceRequireObjectCache {
private PathMappingCache pathMappingCache;
- private NativeWebRequest nativeWebRequest;
- private HttpServletResponse httpResponse;
+ private ThreadLocal<NativeWebRequest> nativeWebRequest = new
ThreadLocal<NativeWebRequest>();
+ private ThreadLocal<HttpServletResponse> httpResponse = new
ThreadLocal<HttpServletResponse>();
public void setPathMappingCache(PathMappingCache pathMappingCache) {
this.pathMappingCache = pathMappingCache;
}
public HttpServletResponse getHttpServletResponse() {
- return httpResponse == null ?
(HttpServletResponse)nativeWebRequest.getNativeResponse() : httpResponse;
+ return httpResponse.get() == null ? (HttpServletResponse)
nativeWebRequest.get().getNativeResponse() : httpResponse.get();
Review comment:
You should clear the two `ThreadLocal`s after the get operation.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services