Author: markt Date: Tue Apr 19 11:14:04 2011 New Revision: 1095026 URL: http://svn.apache.org/viewvc?rev=1095026&view=rev Log: Use a single TLD location cache for a web application rather than one per JSP compilation to speed up JSP compilation.
Modified: tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java tomcat/trunk/java/org/apache/jasper/JspC.java tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java?rev=1095026&r1=1095025&r2=1095026&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java (original) +++ tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java Tue Apr 19 11:14:04 2011 @@ -748,7 +748,7 @@ public final class EmbeddedServletOption // 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); Modified: tomcat/trunk/java/org/apache/jasper/JspC.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/JspC.java?rev=1095026&r1=1095025&r2=1095026&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/JspC.java (original) +++ tomcat/trunk/java/org/apache/jasper/JspC.java Tue Apr 19 11:14:04 2011 @@ -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); } Modified: tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java?rev=1095026&r1=1095025&r2=1095026&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java Tue Apr 19 11:14:04 2011 @@ -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.LogFactor 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.JarScannerCallb 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(); Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1095026&r1=1095025&r2=1095026&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Tue Apr 19 11:14:04 2011 @@ -121,6 +121,10 @@ 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"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org