From 182044bc3c61bde9ab292854d1311cbf1be5ebfd Mon Sep 17 00:00:00 2001 From: rjung Date: Fri, 29 Oct 2010 23:08:59 +0000 Subject: [PATCH] We will no longer continuously update the jspQueue order. Instead only update each JSP once between background task runs. Changes to JspRuntimeContext: - Rename "ticket" to "unloadHandle" - Rename "lastCheck" to "lastCompileCheck" to clarify purpose - Add lastJspQueueUpdate which contains the time of the last run of checkUnload() - Add getter for lastJspQueueUpdate - Background task checkUnload() now only tracks the time of its last execution. Changes to JspServletWrapper: - Rename "ticket" to "unloadHandle" - Replace options.getMaxLoadedJsps() with final field "unloadByCount" - Do no longer move wrapper in jspQueue on each access. Only move once after each run of the background task checkUnload(). git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1028939 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/jasper/compiler/JspRuntimeContext.java | 55 +++++++++------------- .../apache/jasper/servlet/JspServletWrapper.java | 17 ++++--- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/java/org/apache/jasper/compiler/JspRuntimeContext.java b/java/org/apache/jasper/compiler/JspRuntimeContext.java index ef21a5ac4..dff058a84 100644 --- a/java/org/apache/jasper/compiler/JspRuntimeContext.java +++ b/java/org/apache/jasper/compiler/JspRuntimeContext.java @@ -153,7 +153,7 @@ public final class JspRuntimeContext { if (!options.getDevelopment() && appBase != null && options.getCheckInterval() > 0) { - lastCheck = System.currentTimeMillis(); + lastCompileCheck = System.currentTimeMillis(); } if (options.getMaxLoadedJsps() > 0) { @@ -173,7 +173,8 @@ public final class JspRuntimeContext { private final PermissionCollection permissionCollection; private final CodeSource codeSource; private final String classpath; - private volatile long lastCheck = -1L; + private volatile long lastCompileCheck = -1L; + private volatile long lastJspQueueUpdate = System.currentTimeMillis(); /** * Maps JSP pages to their JspServletWrapper's @@ -221,7 +222,7 @@ public final class JspRuntimeContext { * execution of jsp. Destroy any JSP the has been replaced in the queue. * * @param jsw Servlet wrapper for jsp. - * @return a ticket that can be pushed to front of queue at later execution times. + * @return an unloadHandle that can be pushed to front of queue at later execution times. * */ public FastRemovalDequeue.Entry push(JspServletWrapper jsw) { FastRemovalDequeue.Entry entry = jspQueue.push(jsw); @@ -233,12 +234,12 @@ public final class JspRuntimeContext { } /** - * Push ticket for JspServletWrapper to front of the queue. + * Push unloadHandle for JspServletWrapper to front of the queue. * - * @param ticket the ticket for the jsp. + * @param unloadHandle the unloadHandle for the jsp. * */ - public void makeYoungest(FastRemovalDequeue.Entry ticket) { - jspQueue.moveFirst(ticket); + public void makeYoungest(FastRemovalDequeue.Entry unloadHandle) { + jspQueue.moveFirst(unloadHandle); } /** @@ -322,13 +323,13 @@ public final class JspRuntimeContext { */ public void checkCompile() { - if (lastCheck < 0) { + if (lastCompileCheck < 0) { // Checking was disabled return; } long now = System.currentTimeMillis(); - if (now > (lastCheck + (options.getCheckInterval() * 1000L))) { - lastCheck = now; + if (now > (lastCompileCheck + (options.getCheckInterval() * 1000L))) { + lastCompileCheck = now; } else { return; } @@ -361,6 +362,13 @@ public final class JspRuntimeContext { return classpath; } + /** + * Last time the update background task has run + */ + public long getLastJspQueueUpdate() { + return lastJspQueueUpdate; + } + // -------------------------------------------------------- Private Methods @@ -513,31 +521,12 @@ public final class JspRuntimeContext { } } + /** - * Method used by background thread to check if any JSP's should be destroyed. - * If JSP's to be unloaded are found, they will be destroyed. - * Uses the lastCheck time from background compiler to determine if it is time to unload JSP's. + * Method used by background thread to check if any JSP's should be unloaded. */ public void checkUnload() { - if (options.getMaxLoadedJsps() > 0) { - while (unloadJsp()) {} - } - } - - /** - * Checks whether there is a jsp to unload, if one is found, it is destroyed. - * */ - public boolean unloadJsp() { - JspServletWrapper jsw = null; - synchronized(jspQueue) { - if(jspQueue.getSize() > options.getMaxLoadedJsps()) { - jsw = jspQueue.pop(); - } - } - if (jsw != null) { - unloadJspServletWrapper(jsw); - return true; - } - return false; + + lastJspQueueUpdate = System.currentTimeMillis(); } } diff --git a/java/org/apache/jasper/servlet/JspServletWrapper.java b/java/org/apache/jasper/servlet/JspServletWrapper.java index a6dc6e5ae..6a6867296 100644 --- a/java/org/apache/jasper/servlet/JspServletWrapper.java +++ b/java/org/apache/jasper/servlet/JspServletWrapper.java @@ -87,7 +87,9 @@ public class JspServletWrapper { /** Timestamp of last time servlet resource was modified */ private volatile long servletClassLastModifiedTime; private long lastModificationTest = 0L; - private FastRemovalDequeue.Entry ticket; + private long lastUsageTime = System.currentTimeMillis(); + private FastRemovalDequeue.Entry unloadHandle; + private final boolean unloadByCount; /* * JspServletWrapper for JSP pages. @@ -99,6 +101,7 @@ public class JspServletWrapper { this.config = config; this.options = options; this.jspUri = jspUri; + unloadByCount = options.getMaxLoadedJsps() > 0 ? true : false; ctxt = new JspCompilationContext(jspUri, isErrorPage, options, config.getServletContext(), this, rctxt); @@ -119,6 +122,7 @@ public class JspServletWrapper { this.options = options; this.jspUri = tagFilePath; this.tripCount = 0; + unloadByCount = options.getMaxLoadedJsps() > 0 ? true : false; ctxt = new JspCompilationContext(jspUri, tagInfo, options, servletContext, this, rctxt, tagJarResource); @@ -373,12 +377,13 @@ public class JspServletWrapper { /* * (3) Handle limitation of number of loaded Jsps */ - if (options.getMaxLoadedJsps() > 0) { + if (unloadByCount) { synchronized(this) { - if (ticket == null) { - ticket = ctxt.getRuntimeContext().push(this); - } else { - ctxt.getRuntimeContext().makeYoungest(ticket); + if (unloadHandle == null) { + unloadHandle = ctxt.getRuntimeContext().push(this); + } else if (lastUsageTime < ctxt.getRuntimeContext().getLastJspQueueUpdate()) { + ctxt.getRuntimeContext().makeYoungest(unloadHandle); + lastUsageTime = System.currentTimeMillis(); } } } -- 2.11.0