From 93298fc9faed433197c1a16663ed8ebf6f49ce29 Mon Sep 17 00:00:00 2001 From: Ian Chan Date: Sat, 2 Jan 2016 14:41:10 +1300 Subject: [PATCH] Catch RejectedExecutionException in WebAsyncManager Issue: SPR-13836 --- .../request/async/WebAsyncManager.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java index 2322d610271..a20cf23d957 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -21,6 +21,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; +import java.util.concurrent.RejectedExecutionException; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; @@ -306,24 +307,30 @@ public final class WebAsyncManager { interceptorChain.applyBeforeConcurrentHandling(this.asyncWebRequest, callable); startAsyncProcessing(processingContext); - - this.taskExecutor.submit(new Runnable() { - @Override - public void run() { - Object result = null; - try { - interceptorChain.applyPreProcess(asyncWebRequest, callable); - result = callable.call(); + try { + this.taskExecutor.submit(new Runnable() { + @Override + public void run() { + Object result = null; + try { + interceptorChain.applyPreProcess(asyncWebRequest, callable); + result = callable.call(); + } + catch (Throwable ex) { + result = ex; + } + finally { + result = interceptorChain.applyPostProcess(asyncWebRequest, callable, result); + } + setConcurrentResultAndDispatch(result); } - catch (Throwable ex) { - result = ex; - } - finally { - result = interceptorChain.applyPostProcess(asyncWebRequest, callable, result); - } - setConcurrentResultAndDispatch(result); - } - }); + }); + } + catch (RejectedExecutionException ex) { + Object result = interceptorChain.applyPostProcess(this.asyncWebRequest, callable, ex); + setConcurrentResultAndDispatch(result); + throw ex; + } } private void setConcurrentResultAndDispatch(Object result) {