Cache constructor instance in WebAsyncUtils
Issue: SPR-10673
This commit is contained in:
		
							parent
							
								
									55f02db18e
								
							
						
					
					
						commit
						a0f8a894f2
					
				| 
						 | 
					@ -36,6 +36,9 @@ public abstract class WebAsyncUtils {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static final String WEB_ASYNC_MANAGER_ATTRIBUTE = WebAsyncManager.class.getName() + ".WEB_ASYNC_MANAGER";
 | 
						public static final String WEB_ASYNC_MANAGER_ATTRIBUTE = WebAsyncManager.class.getName() + ".WEB_ASYNC_MANAGER";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private static Constructor<?> standardAsyncRequestConstructor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Obtain the {@link WebAsyncManager} for the current request, or if not
 | 
						 * Obtain the {@link WebAsyncManager} for the current request, or if not
 | 
				
			||||||
	 * found, create and associate it with the request.
 | 
						 * found, create and associate it with the request.
 | 
				
			||||||
| 
						 | 
					@ -80,10 +83,12 @@ public abstract class WebAsyncUtils {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static AsyncWebRequest createStandardServletAsyncWebRequest(HttpServletRequest request, HttpServletResponse response) {
 | 
						private static AsyncWebRequest createStandardServletAsyncWebRequest(HttpServletRequest request, HttpServletResponse response) {
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			String className = "org.springframework.web.context.request.async.StandardServletAsyncWebRequest";
 | 
								if (standardAsyncRequestConstructor == null) {
 | 
				
			||||||
			Class<?> clazz = ClassUtils.forName(className, WebAsyncUtils.class.getClassLoader());
 | 
									String className = "org.springframework.web.context.request.async.StandardServletAsyncWebRequest";
 | 
				
			||||||
			Constructor<?> constructor = clazz.getConstructor(HttpServletRequest.class, HttpServletResponse.class);
 | 
									Class<?> clazz = ClassUtils.forName(className, WebAsyncUtils.class.getClassLoader());
 | 
				
			||||||
			return (AsyncWebRequest) BeanUtils.instantiateClass(constructor, request, response);
 | 
									standardAsyncRequestConstructor = clazz.getConstructor(HttpServletRequest.class, HttpServletResponse.class);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return (AsyncWebRequest) BeanUtils.instantiateClass(standardAsyncRequestConstructor, request, response);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		catch (Throwable t) {
 | 
							catch (Throwable t) {
 | 
				
			||||||
			throw new IllegalStateException("Failed to instantiate StandardServletAsyncWebRequest", t);
 | 
								throw new IllegalStateException("Failed to instantiate StandardServletAsyncWebRequest", t);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue