jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daryl Beattie" <dar...@date.com>
Subject RE: Memory Leak in ELEvaluator (cont'd...)
Date Fri, 25 Feb 2005 20:16:31 GMT
Yeah, that's basically it! Dunno why I never thought of using a
scriptlet instead of writing a custom tag... It's probably because
scriptlets are so frowned-upon where I currently work that I hardly ever
consider using them.

One thing I did in one of my tests was actually to print out the size of
the cache in the JSP. So as my JSP refreshed every second, I could watch
the size of the cache climb. This, of course, requires a change to
ELEvaluator.java so that the size of the cache is publicly visible --
perhaps by adding a "getCacheSize()" method.

Although I don't like to have my test JSPs actually display their own
results, the problem with this kind of test is that it can't be easily
converted to a "unit" test; it's results are somewhat subjective.
Because of that, I found that adding the cache size to the JSP eased my
results.

By adding this to ELEvaluator.java:
public static int getELCacheSize() {
	return ELEvaluator.sCachedExpressionStrings.size();
}

You can then change the body of the JSP to:
<body>
	<p>EL Cache Test</p>
	<p>EL Cache Size: <%=ELEvaluator.getELCacheSize()%></p>
</body>

Then you just load the JSP and watch it climb; if it climbs
indefinitely, you've got a bug in the cache. If it climbs to a fixed
size and stops there's no bug. ...And I would personally put the refresh
delay down to 0 just so that the cache is filled up faster... cuz I'm
impatient. :)

- Daryl Beattie


> -----Original Message-----
> From: Kris Schneider [mailto:kris@dotech.com] 
> Sent: Friday, February 25, 2005 1:57 PM
> To: Tag Libraries Developers List
> Subject: Re: Memory Leak in ELEvaluator (cont'd...)
> 
> 
> Here's an approach to dynamically generating unique 
> expressions that might work as a test.
> 
> elcache.jsp:
> ------------
> <%@ page import="java.io.*" %>
> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
> 
> <%
> String genPath = 
> pageContext.getServletContext().getRealPath("/generated.jsp");
> PrintStream ps = null;
> try {
>     ps = new PrintStream(new BufferedOutputStream(new 
> FileOutputStream(genPath, false), 4096));
> 
>     ps.println("<%" + "@ taglib prefix=\"c\" 
> uri=\"http://java.sun.com/jstl/core\" %\>");
>     ps.println("<html><head>");
>     ps.println("<meta http-equiv=\"refresh\" content=\"3; 
> URL=elcache.jsp\">");
>     ps.println("<title>Generated</title>");
>     ps.println("</head><body><ul>");
> 
>     long time = System.currentTimeMillis();
>     for (int i = 0; i < 100; i++) {
>         long value = time + i;
>         String var = "v_" + value;
>         ps.print("<li>");
>         ps.print("<c:set var='" + var + "' value='${" + value 
> + "}'/>");
>         ps.print("<c:out value='${pageScope." + var + "}'/>");
>         ps.println("</li>");
>     }
> 
>     ps.println("</ul></body></html>");
> } catch (FileNotFoundException exc) {
>     exc.printStackTrace();
> } finally {
>     if (ps != null) {
>         ps.close();
>     }
> }
> %>
> 
> <html>
> 
>     <head>
>         <meta http-equiv="refresh" content="3; URL=generated.jsp">
>         <title>EL Cache Test</title>
>     </head>
> 
>     <body>
>         <p>EL Cache Test</p>
>     </body>
> 
> </html>
> 
> If you drop this into TC's $CATALINA_HOME/webapps/ROOT and 
> add the JSTL libs to $CATALINA_HOME/webapps/ROOT/WEB-INF/lib, 
> it should do what you want. I tested this with TC 4.1.31 and 
> Standard 1.0.6, but didn't do any sort of profiling. If you 
> don't see the output from generated.jsp change for each 
> request, try increasing the refresh interval.
> 
> -- 
> Kris Schneider <mailto:kris@dotech.com>
> D.O.Tech       <http://www.dotech.com/>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


Mime
View raw message