Skip to content

Commit 9af1984

Browse files
committed
Cache constructor instance in WebAsyncUtils
Issue: SPR-10673
1 parent 860e56e commit 9af1984

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public abstract class WebAsyncUtils {
3636

3737
public static final String WEB_ASYNC_MANAGER_ATTRIBUTE = WebAsyncManager.class.getName() + ".WEB_ASYNC_MANAGER";
3838

39+
private static Constructor<?> standardAsyncRequestConstructor;
40+
41+
3942
/**
4043
* Obtain the {@link WebAsyncManager} for the current request, or if not
4144
* found, create and associate it with the request.
@@ -80,10 +83,12 @@ public static AsyncWebRequest createAsyncWebRequest(HttpServletRequest request,
8083

8184
private static AsyncWebRequest createStandardServletAsyncWebRequest(HttpServletRequest request, HttpServletResponse response) {
8285
try {
83-
String className = "org.springframework.web.context.request.async.StandardServletAsyncWebRequest";
84-
Class<?> clazz = ClassUtils.forName(className, WebAsyncUtils.class.getClassLoader());
85-
Constructor<?> constructor = clazz.getConstructor(HttpServletRequest.class, HttpServletResponse.class);
86-
return (AsyncWebRequest) BeanUtils.instantiateClass(constructor, request, response);
86+
if (standardAsyncRequestConstructor == null) {
87+
String className = "org.springframework.web.context.request.async.StandardServletAsyncWebRequest";
88+
Class<?> clazz = ClassUtils.forName(className, WebAsyncUtils.class.getClassLoader());
89+
standardAsyncRequestConstructor = clazz.getConstructor(HttpServletRequest.class, HttpServletResponse.class);
90+
}
91+
return (AsyncWebRequest) BeanUtils.instantiateClass(standardAsyncRequestConstructor, request, response);
8792
}
8893
catch (Throwable t) {
8994
throw new IllegalStateException("Failed to instantiate StandardServletAsyncWebRequest", t);

0 commit comments

Comments
 (0)