Use a single TLD location cache for a web application rather than one per JSP compila...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 19 Apr 2011 11:14:04 +0000 (11:14 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 19 Apr 2011 11:14:04 +0000 (11:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1095026 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/EmbeddedServletOptions.java
java/org/apache/jasper/JspC.java
java/org/apache/jasper/compiler/TldLocationsCache.java
webapps/docs/changelog.xml

index 0ab63ab..6c5ddbd 100644 (file)
@@ -748,7 +748,7 @@ public final class EmbeddedServletOptions implements Options {
 
         // Setup the global Tag Libraries location cache for this
         // web-application.
-        tldLocationsCache = new TldLocationsCache(context);
+        tldLocationsCache = TldLocationsCache.getInstance(context);
         
         // Setup the jsp config info for this web app.
         jspConfig = new JspConfig(context);
index 22e43de..bf08865 100644 (file)
@@ -1436,7 +1436,7 @@ public class JspC implements Options {
             context =new JspCServletContext
                 (new PrintWriter(System.out),
                  new URL("file:" + uriRoot.replace('\\','/') + '/'));
-            tldLocationsCache = new TldLocationsCache(context);
+            tldLocationsCache = TldLocationsCache.getInstance(context);
         } catch (MalformedURLException me) {
             System.out.println("**" + me);
         }
index a824016..3d66af6 100644 (file)
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.jasper.compiler;
 
 import java.io.File;
@@ -42,6 +41,7 @@ import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.JarScanner;
 import org.apache.tomcat.JarScannerCallback;
 
+
 /**
  * A container for all tag libraries that are defined "globally"
  * for the web application.
@@ -77,7 +77,9 @@ import org.apache.tomcat.JarScannerCallback;
 
 public class TldLocationsCache {
 
-    private final Log log = LogFactory.getLog(TldLocationsCache.class);
+    private static final Log log = LogFactory.getLog(TldLocationsCache.class);
+
+    private static final String KEY = TldLocationsCache.class.getName();
 
     /**
      * The types of URI one may specify for a tag library
@@ -103,7 +105,7 @@ public class TldLocationsCache {
      */
     private Hashtable<String, TldLocation> mappings;
 
-    private boolean initialized;
+    private volatile boolean initialized;
     private ServletContext ctxt;
 
     /** Constructor. 
@@ -139,6 +141,24 @@ public class TldLocationsCache {
         }
     }
 
+
+    /**
+     * Obtains the TLD location cache for the given {@link ServletContext} and
+     * creates one if one does not currently exist.
+     */
+    public static synchronized TldLocationsCache getInstance(
+            ServletContext ctxt) {
+        if (ctxt == null) {
+            throw new IllegalArgumentException("ServletContext was null");
+        }
+        TldLocationsCache cache = (TldLocationsCache) ctxt.getAttribute(KEY);
+        if (cache == null) {
+            cache = new TldLocationsCache(ctxt);
+            ctxt.setAttribute(KEY, cache);
+        }
+        return cache;
+    }
+
     /**
      * Gets the 'location' of the TLD associated with the given taglib 'uri'.
      *
@@ -189,7 +209,7 @@ public class TldLocationsCache {
      * wonderful arrangements present when Tomcat gets embedded.
      *
      */
-    private void init() throws JasperException {
+    private synchronized void init() throws JasperException {
         if (initialized) return;
         try {
             tldScanWebXml();
index e973b7c..bac873a 100644 (file)
         can easily identify JARs that can be added to the list of JARs to skip.
         (markt)
       </add>
+      <update>
+        Use a single TLD location cache for a web application rather than one
+        per JSP compilation to speed up JSP compilation. (markt)
+      </update>
     </changelog>
   </subsection>
   <subsection name="Web applications">