You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2023/03/26 12:11:17 UTC

[struts] branch WW-5289-executor created (now 1a3af1907)

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch WW-5289-executor
in repository https://gitbox.apache.org/repos/asf/struts.git


      at 1a3af1907 WW-5289 Fixes creating executor to avoid locking JVM on shutdown

This branch includes the following new commits:

     new 1a3af1907 WW-5289 Fixes creating executor to avoid locking JVM on shutdown

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[struts] 01/01: WW-5289 Fixes creating executor to avoid locking JVM on shutdown

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5289-executor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 1a3af1907a3d2401d75f82f9c875cb2c2ac4cccb
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sun Mar 26 14:11:10 2023 +0200

    WW-5289 Fixes creating executor to avoid locking JVM on shutdown
---
 apps/showcase/src/main/resources/struts-wait.xml                     | 5 ++++-
 .../xwork2/config/providers/StrutsDefaultConfigurationProvider.java  | 4 ++++
 core/src/main/java/org/apache/struts2/StrutsConstants.java           | 3 +++
 .../java/org/apache/struts2/config/StrutsBeanSelectionProvider.java  | 3 +++
 .../org/apache/struts2/interceptor/ExecuteAndWaitInterceptor.java    | 5 +++--
 .../org/apache/struts2/interceptor/exec/StrutsExecutorProvider.java  | 2 +-
 core/src/main/resources/struts-beans.xml                             | 3 +++
 7 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/apps/showcase/src/main/resources/struts-wait.xml b/apps/showcase/src/main/resources/struts-wait.xml
index b237dac68..23784b91f 100644
--- a/apps/showcase/src/main/resources/struts-wait.xml
+++ b/apps/showcase/src/main/resources/struts-wait.xml
@@ -25,7 +25,10 @@
 
 <struts>
 
-    <bean type="org.apache.struts2.interceptor.exec.ExecutorProvider" class="org.apache.struts2.showcase.wait.ThreadPoolExecutorProvider"/>
+    <bean type="org.apache.struts2.interceptor.exec.ExecutorProvider" name="threadPool"
+          class="org.apache.struts2.showcase.wait.ThreadPoolExecutorProvider"/>
+
+    <constant name="struts.executor.provider" value="threadPool"/>
 
     <package name="wait" extends="struts-default" namespace="/wait">
         <default-action-ref name="index"/>
diff --git a/core/src/main/java/com/opensymphony/xwork2/config/providers/StrutsDefaultConfigurationProvider.java b/core/src/main/java/com/opensymphony/xwork2/config/providers/StrutsDefaultConfigurationProvider.java
index 1f49cc11b..2c304ec82 100644
--- a/core/src/main/java/com/opensymphony/xwork2/config/providers/StrutsDefaultConfigurationProvider.java
+++ b/core/src/main/java/com/opensymphony/xwork2/config/providers/StrutsDefaultConfigurationProvider.java
@@ -118,6 +118,8 @@ import org.apache.struts2.conversion.StrutsTypeConverterCreator;
 import org.apache.struts2.conversion.StrutsTypeConverterHolder;
 import org.apache.struts2.dispatcher.HttpParameters;
 import org.apache.struts2.dispatcher.Parameter;
+import org.apache.struts2.interceptor.exec.ExecutorProvider;
+import org.apache.struts2.interceptor.exec.StrutsExecutorProvider;
 import org.apache.struts2.url.QueryStringBuilder;
 import org.apache.struts2.url.QueryStringParser;
 import org.apache.struts2.url.StrutsQueryStringBuilder;
@@ -242,6 +244,8 @@ public class StrutsDefaultConfigurationProvider implements ConfigurationProvider
             .factory(QueryStringParser.class, StrutsQueryStringParser.class, Scope.SINGLETON)
             .factory(UrlEncoder.class, StrutsUrlEncoder.class, Scope.SINGLETON)
             .factory(UrlDecoder.class, StrutsUrlDecoder.class, Scope.SINGLETON)
+
+            .factory(ExecutorProvider.class, StrutsExecutorProvider.class, Scope.SINGLETON)
         ;
 
         props.setProperty(StrutsConstants.STRUTS_ENABLE_DYNAMIC_METHOD_INVOCATION, Boolean.FALSE.toString());
diff --git a/core/src/main/java/org/apache/struts2/StrutsConstants.java b/core/src/main/java/org/apache/struts2/StrutsConstants.java
index b6b5ca158..183c0aaf7 100644
--- a/core/src/main/java/org/apache/struts2/StrutsConstants.java
+++ b/core/src/main/java/org/apache/struts2/StrutsConstants.java
@@ -463,4 +463,7 @@ public final class StrutsConstants {
 
     /** A global flag to set property {@link org.apache.struts2.components.Checkbox#setSubmitUnchecked(String)} */
     public static final String STRUTS_UI_CHECKBOX_SUBMIT_UNCHECKED = "struts.ui.checkbox.submitUnchecked";
+
+    /** See {@link org.apache.struts2.interceptor.exec.ExecutorProvider} */
+    public static final String STRUTS_EXECUTOR_PROVIDER = "struts.executor.provider";
 }
diff --git a/core/src/main/java/org/apache/struts2/config/StrutsBeanSelectionProvider.java b/core/src/main/java/org/apache/struts2/config/StrutsBeanSelectionProvider.java
index 06385f28f..c80494f35 100644
--- a/core/src/main/java/org/apache/struts2/config/StrutsBeanSelectionProvider.java
+++ b/core/src/main/java/org/apache/struts2/config/StrutsBeanSelectionProvider.java
@@ -66,6 +66,7 @@ import org.apache.struts2.dispatcher.DispatcherErrorHandler;
 import org.apache.struts2.dispatcher.StaticContentLoader;
 import org.apache.struts2.dispatcher.mapper.ActionMapper;
 import org.apache.struts2.dispatcher.multipart.MultiPartRequest;
+import org.apache.struts2.interceptor.exec.ExecutorProvider;
 import org.apache.struts2.url.QueryStringBuilder;
 import org.apache.struts2.url.QueryStringParser;
 import org.apache.struts2.url.UrlDecoder;
@@ -438,6 +439,8 @@ public class StrutsBeanSelectionProvider extends AbstractBeanSelectionProvider {
         alias(UrlEncoder.class, StrutsConstants.STRUTS_URL_ENCODER, builder, props, Scope.SINGLETON);
         alias(UrlDecoder.class, StrutsConstants.STRUTS_URL_DECODER, builder, props, Scope.SINGLETON);
 
+        alias(ExecutorProvider.class, StrutsConstants.STRUTS_EXECUTOR_PROVIDER, builder, props, Scope.SINGLETON);
+
         switchDevMode(props);
     }
 
diff --git a/core/src/main/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptor.java
index 4a5cb91b4..7a022c9cb 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptor.java
@@ -197,7 +197,7 @@ public class ExecuteAndWaitInterceptor extends MethodFilterInterceptor {
         this.container = container;
     }
 
-    @Inject(required = false)
+    @Inject
     public void setExecutorProvider(ExecutorProvider executorProvider) {
         this.executor = executorProvider;
     }
@@ -387,7 +387,8 @@ public class ExecuteAndWaitInterceptor extends MethodFilterInterceptor {
     public void init() {
         super.init();
         if (executor == null) {
-            executor = new StrutsExecutorProvider();
+            LOG.debug("Using: {} as ExecutorProvider", StrutsExecutorProvider.class.getSimpleName());
+            executor = container.getInstance(StrutsExecutorProvider.class);
         }
     }
 
diff --git a/core/src/main/java/org/apache/struts2/interceptor/exec/StrutsExecutorProvider.java b/core/src/main/java/org/apache/struts2/interceptor/exec/StrutsExecutorProvider.java
index 7370f318a..0e0ba966d 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/exec/StrutsExecutorProvider.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/exec/StrutsExecutorProvider.java
@@ -31,7 +31,7 @@ public class StrutsExecutorProvider implements ExecutorProvider {
     private final ExecutorService executor;
 
     public StrutsExecutorProvider() {
-        this.executor = Executors.newSingleThreadExecutor();
+        this.executor = Executors.newFixedThreadPool(2);
     }
 
     @Override
diff --git a/core/src/main/resources/struts-beans.xml b/core/src/main/resources/struts-beans.xml
index eac1ff8be..7f98e4db5 100644
--- a/core/src/main/resources/struts-beans.xml
+++ b/core/src/main/resources/struts-beans.xml
@@ -245,4 +245,7 @@
     <bean type="org.apache.struts2.url.UrlDecoder" name="strutsUrlDecoder"
           class="org.apache.struts2.url.StrutsUrlDecoder" scope="singleton"/>
 
+    <bean type="org.apache.struts2.interceptor.exec.ExecutorProvider" name="struts"
+          class="org.apache.struts2.interceptor.exec.StrutsExecutorProvider"/>
+
 </struts>