Skip to content

Commit 365f39e

Browse files
authored
Merge pull request apache#673 from apache/WW-5289-executor
[WW-5289] Fixes creating executor to avoid locking JVM on shutdown
2 parents babbd5e + 1a3af19 commit 365f39e

File tree

7 files changed

+21
-4
lines changed

7 files changed

+21
-4
lines changed

apps/showcase/src/main/resources/struts-wait.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525

2626
<struts>
2727

28-
<bean type="org.apache.struts2.interceptor.exec.ExecutorProvider" class="org.apache.struts2.showcase.wait.ThreadPoolExecutorProvider"/>
28+
<bean type="org.apache.struts2.interceptor.exec.ExecutorProvider" name="threadPool"
29+
class="org.apache.struts2.showcase.wait.ThreadPoolExecutorProvider"/>
30+
31+
<constant name="struts.executor.provider" value="threadPool"/>
2932

3033
<package name="wait" extends="struts-default" namespace="/wait">
3134
<default-action-ref name="index"/>

core/src/main/java/com/opensymphony/xwork2/config/providers/StrutsDefaultConfigurationProvider.java

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@
118118
import org.apache.struts2.conversion.StrutsTypeConverterHolder;
119119
import org.apache.struts2.dispatcher.HttpParameters;
120120
import org.apache.struts2.dispatcher.Parameter;
121+
import org.apache.struts2.interceptor.exec.ExecutorProvider;
122+
import org.apache.struts2.interceptor.exec.StrutsExecutorProvider;
121123
import org.apache.struts2.url.QueryStringBuilder;
122124
import org.apache.struts2.url.QueryStringParser;
123125
import org.apache.struts2.url.StrutsQueryStringBuilder;
@@ -242,6 +244,8 @@ public void register(ContainerBuilder builder, LocatableProperties props)
242244
.factory(QueryStringParser.class, StrutsQueryStringParser.class, Scope.SINGLETON)
243245
.factory(UrlEncoder.class, StrutsUrlEncoder.class, Scope.SINGLETON)
244246
.factory(UrlDecoder.class, StrutsUrlDecoder.class, Scope.SINGLETON)
247+
248+
.factory(ExecutorProvider.class, StrutsExecutorProvider.class, Scope.SINGLETON)
245249
;
246250

247251
props.setProperty(StrutsConstants.STRUTS_ENABLE_DYNAMIC_METHOD_INVOCATION, Boolean.FALSE.toString());

core/src/main/java/org/apache/struts2/StrutsConstants.java

+3
Original file line numberDiff line numberDiff line change
@@ -466,4 +466,7 @@ public final class StrutsConstants {
466466

467467
/** A global flag to set property {@link org.apache.struts2.components.Checkbox#setSubmitUnchecked(String)} */
468468
public static final String STRUTS_UI_CHECKBOX_SUBMIT_UNCHECKED = "struts.ui.checkbox.submitUnchecked";
469+
470+
/** See {@link org.apache.struts2.interceptor.exec.ExecutorProvider} */
471+
public static final String STRUTS_EXECUTOR_PROVIDER = "struts.executor.provider";
469472
}

core/src/main/java/org/apache/struts2/config/StrutsBeanSelectionProvider.java

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.apache.struts2.dispatcher.StaticContentLoader;
6767
import org.apache.struts2.dispatcher.mapper.ActionMapper;
6868
import org.apache.struts2.dispatcher.multipart.MultiPartRequest;
69+
import org.apache.struts2.interceptor.exec.ExecutorProvider;
6970
import org.apache.struts2.url.QueryStringBuilder;
7071
import org.apache.struts2.url.QueryStringParser;
7172
import org.apache.struts2.url.UrlDecoder;
@@ -438,6 +439,8 @@ public void register(ContainerBuilder builder, LocatableProperties props) {
438439
alias(UrlEncoder.class, StrutsConstants.STRUTS_URL_ENCODER, builder, props, Scope.SINGLETON);
439440
alias(UrlDecoder.class, StrutsConstants.STRUTS_URL_DECODER, builder, props, Scope.SINGLETON);
440441

442+
alias(ExecutorProvider.class, StrutsConstants.STRUTS_EXECUTOR_PROVIDER, builder, props, Scope.SINGLETON);
443+
441444
switchDevMode(props);
442445
}
443446

core/src/main/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptor.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public void setContainer(Container container) {
197197
this.container = container;
198198
}
199199

200-
@Inject(required = false)
200+
@Inject
201201
public void setExecutorProvider(ExecutorProvider executorProvider) {
202202
this.executor = executorProvider;
203203
}
@@ -387,7 +387,8 @@ public void setExecuteAfterValidationPass(boolean executeAfterValidationPass) {
387387
public void init() {
388388
super.init();
389389
if (executor == null) {
390-
executor = new StrutsExecutorProvider();
390+
LOG.debug("Using: {} as ExecutorProvider", StrutsExecutorProvider.class.getSimpleName());
391+
executor = container.getInstance(StrutsExecutorProvider.class);
391392
}
392393
}
393394

core/src/main/java/org/apache/struts2/interceptor/exec/StrutsExecutorProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class StrutsExecutorProvider implements ExecutorProvider {
3131
private final ExecutorService executor;
3232

3333
public StrutsExecutorProvider() {
34-
this.executor = Executors.newSingleThreadExecutor();
34+
this.executor = Executors.newFixedThreadPool(2);
3535
}
3636

3737
@Override

core/src/main/resources/struts-beans.xml

+3
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,7 @@
245245
<bean type="org.apache.struts2.url.UrlDecoder" name="strutsUrlDecoder"
246246
class="org.apache.struts2.url.StrutsUrlDecoder" scope="singleton"/>
247247

248+
<bean type="org.apache.struts2.interceptor.exec.ExecutorProvider" name="struts"
249+
class="org.apache.struts2.interceptor.exec.StrutsExecutorProvider"/>
250+
248251
</struts>

0 commit comments

Comments
 (0)