Would you consider putting the time unit (seconds) in the param name or at 
least in _all_ the javadoc?  Without documentation I would expect the natural 
time unit to be minutes.

thanks
david jencks

On Oct 29, 2010, at 4:22 PM, rj...@apache.org wrote:

> Author: rjung
> Date: Fri Oct 29 23:22:35 2010
> New Revision: 1028940
> 
> URL: http://svn.apache.org/viewvc?rev=1028940&view=rev
> Log:
> Add new JSP init parameter "jspIdleTimeout".
> 
> If set > 0 (default -1), a background task
> will unload all JSPs being idle longer than this
> time in seconds.
> 
> Modified:
>    tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java
>    tomcat/trunk/java/org/apache/jasper/JspC.java
>    tomcat/trunk/java/org/apache/jasper/Options.java
>    tomcat/trunk/java/org/apache/jasper/compiler/JspRuntimeContext.java
>    tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties
>    tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java
> 
> Modified: tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java
> URL: 
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java?rev=1028940&r1=1028939&r2=1028940&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java (original)
> +++ tomcat/trunk/java/org/apache/jasper/EmbeddedServletOptions.java Fri Oct 
> 29 23:22:35 2010
> @@ -189,11 +189,17 @@ public final class EmbeddedServletOption
> 
> 
>     /**
> -     * The maxim number of loaded jsps per web-application. If there are more
> +     * The maximum number of loaded jsps per web-application. If there are 
> more
>      * jsps loaded, they will be unloaded.
>      */
>     private int maxLoadedJsps = -1;
> 
> +    /**
> +     * The idle time after which a JSP is unloaded.
> +     * If unset or less or equal than 0, no jsps are unloaded.
> +     */
> +    private int jspIdleTimeout = -1;
> +
>     public String getProperty(String name ) {
>         return settings.getProperty( name );
>     }
> @@ -391,14 +397,22 @@ public final class EmbeddedServletOption
>     }
> 
>     /**
> -     * Should any jsps be unloaded? If set to a value greater than 0 
> eviction of jsps
> -     * is started. Default: -1
> -     * */
> +     * Should jsps be unloaded if to many are loaded?
> +     * If set to a value greater than 0 eviction of jsps is started. 
> Default: -1
> +     */
>     public int getMaxLoadedJsps() {
>         return maxLoadedJsps;
>     }
> 
>     /**
> +     * Should any jsps be unloaded when being idle for to long?
> +     * If set to a value greater than 0 eviction of jsps is started. 
> Default: -1
> +     */
> +    public int getJspIdleTimeout() {
> +        return jspIdleTimeout;
> +    }
> +
> +    /**
>      * Create an EmbeddedServletOptions object using data available from
>      * ServletConfig and ServletContext. 
>      */
> @@ -689,6 +703,17 @@ public final class EmbeddedServletOption
>                 }
>             }
>         }
> +        
> +        String jspIdleTimeout = config.getInitParameter("jspIdleTimeout");
> +        if (jspIdleTimeout != null) {
> +            try {
> +                this.jspIdleTimeout = Integer.parseInt(jspIdleTimeout);
> +            } catch(NumberFormatException ex) {
> +                if (log.isWarnEnabled()) {
> +                    
> log.warn(Localizer.getMessage("jsp.warning.jspIdleTimeout", 
> ""+this.jspIdleTimeout));
> +                }
> +            }
> +        }
> 
>         // Setup the global Tag Libraries location cache for this
>         // web-application.
> 
> Modified: tomcat/trunk/java/org/apache/jasper/JspC.java
> URL: 
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/JspC.java?rev=1028940&r1=1028939&r2=1028940&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/jasper/JspC.java (original)
> +++ tomcat/trunk/java/org/apache/jasper/JspC.java Fri Oct 29 23:22:35 2010
> @@ -447,6 +447,10 @@ public class JspC implements Options {
>         return -1;
>     }
> 
> +    public int getJspIdleTimeout() {
> +        return -1;
> +    }
> +
>     /**
>      * {...@inheritdoc}
>      */
> 
> Modified: tomcat/trunk/java/org/apache/jasper/Options.java
> URL: 
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/Options.java?rev=1028940&r1=1028939&r2=1028940&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/jasper/Options.java (original)
> +++ tomcat/trunk/java/org/apache/jasper/Options.java Fri Oct 29 23:22:35 2010
> @@ -222,9 +222,15 @@ public interface Options {
>     public Map<String, TagLibraryInfo> getCache();
> 
>     /**
> -     * The maxim number of loaded jsps per web-application. If there are more
> +     * The maximum number of loaded jsps per web-application. If there are 
> more
>      * jsps loaded, they will be unloaded. If unset or less than 0, no jsps
>      * are unloaded.
>      */
>     public int getMaxLoadedJsps();
> +    
> +    /**
> +     * The idle time after which a JSP is unloaded.
> +     * If unset or less or equal than 0, no jsps are unloaded.
> +     */
> +    public int getJspIdleTimeout();
> }
> 
> Modified: tomcat/trunk/java/org/apache/jasper/compiler/JspRuntimeContext.java
> URL: 
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/JspRuntimeContext.java?rev=1028940&r1=1028939&r2=1028940&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/jasper/compiler/JspRuntimeContext.java 
> (original)
> +++ tomcat/trunk/java/org/apache/jasper/compiler/JspRuntimeContext.java Fri 
> Oct 29 23:22:35 2010
> @@ -160,6 +160,7 @@ public final class JspRuntimeContext {
>             jspQueue = new 
> FastRemovalDequeue<JspServletWrapper>(options.getMaxLoadedJsps());
>         }
> 
> +        jspIdleTimeout = options.getJspIdleTimeout() * 1000;
>     }
> 
>     // ----------------------------------------------------- Instance 
> Variables
> @@ -175,6 +176,7 @@ public final class JspRuntimeContext {
>     private final String classpath;
>     private volatile long lastCompileCheck = -1L;
>     private volatile long lastJspQueueUpdate = System.currentTimeMillis();
> +    private long jspIdleTimeout;
> 
>     /**
>      * Maps JSP pages to their JspServletWrapper's
> @@ -527,6 +529,22 @@ public final class JspRuntimeContext {
>      */
>     public void checkUnload() {
> 
> -        lastJspQueueUpdate = System.currentTimeMillis();
> +        long now = System.currentTimeMillis();
> +        if (jspIdleTimeout > 0) {
> +            long unloadBefore = now - jspIdleTimeout;
> +            Object [] wrappers = jsps.values().toArray();
> +            for (int i = 0; i < wrappers.length; i++ ) {
> +                JspServletWrapper jsw = (JspServletWrapper)wrappers[i];
> +                synchronized(jsw) {
> +                    if (jsw.getLastUsageTime() < unloadBefore) {
> +                        if (jspQueue != null) {
> +                            jspQueue.remove(jsw.getUnloadHandle());
> +                        }
> +                        unloadJspServletWrapper(jsw);
> +                    }
> +                }
> +            }
> +        }
> +        lastJspQueueUpdate = now;
>     }
> }
> 
> Modified: 
> tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties
> URL: 
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties?rev=1028940&r1=1028939&r2=1028940&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties 
> (original)
> +++ tomcat/trunk/java/org/apache/jasper/resources/LocalStrings.properties Fri 
> Oct 29 23:22:35 2010
> @@ -177,6 +177,7 @@ jsp.warning.genchararray=Warning: Invali
> jsp.warning.suppressSmap=Warning: Invalid value for the initParam 
> suppressSmap. Will use the default value of \"false\"
> jsp.warning.displaySourceFragment=Warning: Invalid value for the initParam 
> displaySourceFragment. Will use the default value of \"true\"
> jsp.warning.maxLoadedJsps=Warning: Invalid value for the initParam 
> maxLoadedJsps. Will use the default value of \"-1\"
> +jsp.warning.jspIdleTimeout=Warning: Invalid value for the initParam 
> jspIdleTimeout. Will use the default value of \"-1\"
> jsp.error.badtaglib=Unable to open taglibrary {0} : {1}
> jsp.error.badGetReader=Cannot create a reader when the stream is not buffered
> jsp.warning.unknown.element.in.taglib=Unknown element ({0}) in taglib
> @@ -470,4 +471,4 @@ jsp.warning.noJarScanner=Warning: No org
> jsp.error.bug48498=Unable to display JSP extract. Probably due to an XML 
> parser bug (see Tomcat bug 48498 for details).
> 
> # UniqueAttributesImpl
> -jsp.error.duplicateqname=An attribute with duplicate qualified name [{0}] 
> was found. Attribute qualified names must be unique within an element.
> \ No newline at end of file
> +jsp.error.duplicateqname=An attribute with duplicate qualified name [{0}] 
> was found. Attribute qualified names must be unique within an element.
> 
> Modified: tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java
> URL: 
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java?rev=1028940&r1=1028939&r2=1028940&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java 
> (original)
> +++ tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java Fri 
> Oct 29 23:22:35 2010
> @@ -89,7 +89,9 @@ public class JspServletWrapper {
>     private long lastModificationTest = 0L;
>     private long lastUsageTime = System.currentTimeMillis();
>     private FastRemovalDequeue<JspServletWrapper>.Entry unloadHandle;
> +    private final boolean unloadAllowed;
>     private final boolean unloadByCount;
> +    private final boolean unloadByIdle;
> 
>     /*
>      * JspServletWrapper for JSP pages.
> @@ -102,6 +104,8 @@ public class JspServletWrapper {
>         this.options = options;
>         this.jspUri = jspUri;
>         unloadByCount = options.getMaxLoadedJsps() > 0 ? true : false;
> +        unloadByIdle = options.getJspIdleTimeout() > 0 ? true : false;
> +        unloadAllowed = unloadByCount || unloadByIdle ? true : false;
>         ctxt = new JspCompilationContext(jspUri, isErrorPage, options,
>                                          config.getServletContext(),
>                                          this, rctxt);
> @@ -123,6 +127,8 @@ public class JspServletWrapper {
>         this.jspUri = tagFilePath;
>         this.tripCount = 0;
>         unloadByCount = options.getMaxLoadedJsps() > 0 ? true : false;
> +        unloadByIdle = options.getJspIdleTimeout() > 0 ? true : false;
> +        unloadAllowed = unloadByCount || unloadByIdle ? true : false;
>         ctxt = new JspCompilationContext(jspUri, tagInfo, options,
>                                          servletContext, this, rctxt,
>                                          tagJarResource);
> @@ -296,6 +302,10 @@ public class JspServletWrapper {
>         return jspUri;
>     }
> 
> +    public FastRemovalDequeue<JspServletWrapper>.Entry getUnloadHandle() {
> +        return unloadHandle;
> +    }
> +
>     public void service(HttpServletRequest request, 
>                         HttpServletResponse response,
>                         boolean precompile)
> @@ -377,13 +387,19 @@ public class JspServletWrapper {
>             /*
>              * (3) Handle limitation of number of loaded Jsps
>              */
> -            if (unloadByCount) {
> +            if (unloadAllowed) {
>                 synchronized(this) {
> -                    if (unloadHandle == null) {
> -                        unloadHandle = ctxt.getRuntimeContext().push(this);
> -                    } else if (lastUsageTime < 
> ctxt.getRuntimeContext().getLastJspQueueUpdate()) {
> -                        ctxt.getRuntimeContext().makeYoungest(unloadHandle);
> -                        lastUsageTime = System.currentTimeMillis();
> +                    if (unloadByCount) {
> +                        if (unloadHandle == null) {
> +                            unloadHandle = 
> ctxt.getRuntimeContext().push(this);
> +                        } else if (lastUsageTime < 
> ctxt.getRuntimeContext().getLastJspQueueUpdate()) {
> +                            
> ctxt.getRuntimeContext().makeYoungest(unloadHandle);
> +                            lastUsageTime = System.currentTimeMillis();
> +                        }
> +                    } else {
> +                        if (lastUsageTime < 
> ctxt.getRuntimeContext().getLastJspQueueUpdate()) {
> +                            lastUsageTime = System.currentTimeMillis();
> +                        }
>                     }
>                 }
>             }
> @@ -469,6 +485,13 @@ public class JspServletWrapper {
>     }
> 
>     /**
> +     * @return the lastUsageTime.
> +     */
> +    public long getLastUsageTime() {
> +        return lastUsageTime;
> +    }
> +
> +    /**
>      * <p>Attempts to construct a JasperException that contains helpful 
> information
>      * about what went wrong. Uses the JSP compiler system to translate the 
> line
>      * number in the generated servlet that originated the exception to a line
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: dev-h...@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to