Bug 28282

Summary: Performance problems with ExpressionEvaluatorManager
Product: Taglibs Reporter: Richard Kraft <rich_kraft>
Component: Standard TaglibAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED DUPLICATE    
Severity: major    
Priority: P3    
Version: 1.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Remove synchronized from the getEvaluatorByName method

Description Richard Kraft 2004-04-08 14:05:48 UTC
ExpressionEvaluatorManager has a synchronized method that causes every use of
evaluate to block.  This causes major issues when the taglibs are used in a high
throughput environment.


I have patched the code as indicated below:

--- ExpressionEvaluatorManager.java.orig	2004-04-08 03:42:02.000000000 -0500
+++ ExpressionEvaluatorManager.java	2004-04-08 08:58:40.302582400 -0500
@@ -99,20 +99,22 @@
      * Gets an ExpressionEvaluator from the cache, or seeds the cache
      * if we haven't seen a particular ExpressionEvaluator before.
      */
-    public static synchronized
-	    ExpressionEvaluator getEvaluatorByName(String name)
-            throws JspException {
+    public static ExpressionEvaluator getEvaluatorByName(String name) throws
JspException
+    {
+        Object oEvaluator = nameMap.get(name);
+        if (oEvaluator != null)
+            return ((ExpressionEvaluator) oEvaluator);
         try {
-
-            Object oEvaluator = nameMap.get(name);
-            if (oEvaluator == null) {
-                ExpressionEvaluator e = (ExpressionEvaluator)
-                    Class.forName(name).newInstance();
-                nameMap.put(name, e);
-                return (e);
-            } else
+                synchronized (nameMap)
+                {
+                    oEvaluator = nameMap.get(name);
+                    if (oEvaluator != null)
+                        return ((ExpressionEvaluator) oEvaluator);
+                    ExpressionEvaluator e = (ExpressionEvaluator)
Class.forName(name).newInstance();
+                    nameMap.put(name, e);
+                    oEvaluator = e;
+                }
                 return ((ExpressionEvaluator) oEvaluator);
-
         } catch (ClassCastException ex) {
             // just to display a better error message
             throw new JspException("invalid ExpressionEvaluator: " +
Comment 1 Richard Kraft 2004-04-08 14:06:59 UTC
Created attachment 11184 [details]
Remove synchronized from the getEvaluatorByName method
Comment 2 Richard Kraft 2004-04-08 16:37:49 UTC

*** This bug has been marked as a duplicate of 25967 ***