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 2020/04/13 07:47:27 UTC

[struts] branch action-context-boost updated: WW-4789 WW-3788 Avoids unneeded binds to ThreadLocal

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

lukaszlenart pushed a commit to branch action-context-boost
in repository https://gitbox.apache.org/repos/asf/struts.git


The following commit(s) were added to refs/heads/action-context-boost by this push:
     new 6279e6d  WW-4789 WW-3788 Avoids unneeded binds to ThreadLocal
6279e6d is described below

commit 6279e6dd166bf1fa79378d0e317cd0dbebdd91a6
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Mon Apr 13 09:47:19 2020 +0200

    WW-4789 WW-3788 Avoids unneeded binds to ThreadLocal
---
 .../com/opensymphony/xwork2/ActionContext.java     |  4 +--
 .../xwork2/DefaultActionInvocation.java            | 20 +++---------
 .../xwork2/ognl/OgnlValueStackFactory.java         | 37 +++++-----------------
 3 files changed, 15 insertions(+), 46 deletions(-)

diff --git a/core/src/main/java/com/opensymphony/xwork2/ActionContext.java b/core/src/main/java/com/opensymphony/xwork2/ActionContext.java
index 3c9d0e5..e4d9f73 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ActionContext.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ActionContext.java
@@ -242,7 +242,7 @@ public class ActionContext implements Serializable {
      * @return the context map.
      */
     public Map<String, Object> getContextMap() {
-        return getContext().context;
+        return context;
     }
 
     /**
@@ -524,7 +524,7 @@ public class ActionContext implements Serializable {
 
     public ActionContext withExtraContext(Map<String, Object> extraContext) {
         if (extraContext != null) {
-            getContext().context.putAll(extraContext);
+            context.putAll(extraContext);
         }
         return this;
     }
diff --git a/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java b/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
index acf7a65..6ca0c92 100644
--- a/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
+++ b/core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
@@ -324,7 +324,6 @@ public class DefaultActionInvocation implements ActionInvocation {
     }
 
     protected Map<String, Object> createContextMap() {
-        ActionContext oldContext = ActionContext.getContext();
         ActionContext actionContext;
 
         if (extraContext != null && extraContext.containsKey(ActionContext.VALUE_STACK)) {
@@ -345,20 +344,11 @@ public class DefaultActionInvocation implements ActionInvocation {
             actionContext = stack.getActionContext();
         }
 
-        try {
-            return actionContext
-                .bind()
-                .withExtraContext(extraContext)
-                .withActionInvocation(this)
-                .withContainer(container)
-                .getContextMap();
-        } finally {
-            ActionContext.clear();
-            if (oldContext != null) {
-                LOG.debug("Re-binding the old context");
-                oldContext.bind();
-            }
-        }
+        return actionContext
+            .withExtraContext(extraContext)
+            .withActionInvocation(this)
+            .withContainer(container)
+            .getContextMap();
     }
 
     /**
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java
index d19fd6b..267a3c8 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java
@@ -18,7 +18,6 @@
  */
 package com.opensymphony.xwork2.ognl;
 
-import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.TextProvider;
 import com.opensymphony.xwork2.conversion.NullHandler;
 import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
@@ -65,40 +64,20 @@ public class OgnlValueStackFactory implements ValueStackFactory {
         ValueStack stack = new OgnlValueStack(xworkConverter, compoundRootAccessor, textProvider,
             containerAllowsStaticMethodAccess(), containerAllowsStaticFieldAccess());
         container.inject(stack);
-        ActionContext oldContext = ActionContext.getContext();
-        try {
-            return stack.getActionContext()
-                .bind()
-                .withContainer(container)
-                .withValueStack(stack)
-                .getValueStack();
-        } finally {
-            ActionContext.clear();
-            if (oldContext != null) {
-                LOG.debug("Re-binding the old context");
-                oldContext.bind();
-            }
-        }
+        return stack.getActionContext()
+            .withContainer(container)
+            .withValueStack(stack)
+            .getValueStack();
     }
 
     public ValueStack createValueStack(ValueStack stack) {
         ValueStack result = new OgnlValueStack(stack, xworkConverter, compoundRootAccessor,
             containerAllowsStaticMethodAccess(), containerAllowsStaticFieldAccess());
         container.inject(result);
-        ActionContext oldContext = ActionContext.getContext();
-        try {
-            return result.getActionContext()
-                .bind()
-                .withContainer(container)
-                .withValueStack(result)
-                .getValueStack();
-        } finally {
-            ActionContext.clear();
-            if (oldContext != null) {
-                LOG.debug("Re-binding the old context");
-                oldContext.bind();
-            }
-        }
+        return result.getActionContext()
+            .withContainer(container)
+            .withValueStack(result)
+            .getValueStack();
     }
 
     @Inject