From: markt Date: Tue, 19 Apr 2011 11:14:04 +0000 (+0000) Subject: Use a single TLD location cache for a web application rather than one per JSP compila... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=c366a94de6a2f0a783ea2c2bf2b6c613aba959a4;p=tomcat7.0 Use a single TLD location cache for a web application rather than one per JSP compilation to speed up JSP compilation. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1095026 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/jasper/EmbeddedServletOptions.java b/java/org/apache/jasper/EmbeddedServletOptions.java index 0ab63ab3b..6c5ddbd08 100644 --- a/java/org/apache/jasper/EmbeddedServletOptions.java +++ b/java/org/apache/jasper/EmbeddedServletOptions.java @@ -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); diff --git a/java/org/apache/jasper/JspC.java b/java/org/apache/jasper/JspC.java index 22e43de2a..bf0886507 100644 --- a/java/org/apache/jasper/JspC.java +++ b/java/org/apache/jasper/JspC.java @@ -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); } diff --git a/java/org/apache/jasper/compiler/TldLocationsCache.java b/java/org/apache/jasper/compiler/TldLocationsCache.java index a824016c0..3d66af623 100644 --- a/java/org/apache/jasper/compiler/TldLocationsCache.java +++ b/java/org/apache/jasper/compiler/TldLocationsCache.java @@ -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 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(); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index e973b7c3f..bac873aca 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -121,6 +121,10 @@ can easily identify JARs that can be added to the list of JARs to skip. (markt) + + Use a single TLD location cache for a web application rather than one + per JSP compilation to speed up JSP compilation. (markt) +