velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apa...@recks.org
Subject Re: Template cache _kinda_ works?
Date Tue, 08 May 2007 07:44:34 GMT
Hi,

I have not tested this with Tomcat 5.5, but I beleive it is
worth a try to observe some internals of running Java
processes.

Java 1.5 SE (not with JRE) comes with a set of tools to check
a running Java process, see:

  http://java.sun.com/j2se/1.5.0/docs/tooldocs/index.html

and the links to the "Monitoring and Management Tools"
(jconsole, jps, jstat, jstatd) and the "Troubleshooting Tools"
(jinfo, jmap, jsadebugd, jstack).

With `jps` you can list the PIDs of the running java processes
to be used with most of the other tools. Look at the `jps`
command-line options to dump more info on the environment.
Also `jmap -histo <pid>` is good for non-intrusive profiling
to detect memory leaks, as well as for seeing the classloaders.

Cheers,
Christoph


Bensman, Jeff [EESUS Non J&J] wrote:
> Will,
> 
> Thank you for taking the time to put together the sample project.  I've run
> that in my environment, and as you say, it runs as expected!  
> 
> Per your initial questions, I have not changed the max size of the cache. 
> 
> I am running in a web app, but I'm confident it's not a caching issue on the
> browser.  I'm stepping through the source code, including velocity source
> code, in the Eclipse debugger on Tomcat 5.5.
> 
> After an edit to my template, the Modified Date shown in Windows Explorer is
> updating.  If I set a breakpoint in the isSourceModified() method of
> Velocity's FileResourceLoader, it properly returns true after an edit to the
> template.  And then at another breakpoint in the merge() method of Template,
> I look at a toString() on the "data" property of the Template class, and it
> shows the new, edited template content.  But within that merge() method, the
> line that reads:
>     ( (SimpleNode) data ).render( ica, writer);
> seems to result in a writer that holds an old version of the template,
> ignoring the new stuff in the "data" property of the Template.
> 
> I get a little lost trying to step through that render() method.  Can you
> recommend any key things I could look at that might reveal what's happening?
> 
> On a different note, here are the differences I noticed between your
> VelocityWebTest test project and my project...
> 
> 1) your template is inside the file system of your web app, mine is not
> 2) you're using the version of the velocity JAR with dependencies, my app
> has the dependencies separate from the velocity jar
> 3) when I set the velocity properties before init() I specify a
> "velocimacro.library" (which works fine)
> 
> But for all 3 cases I modified my app to be configured/run like yours, and
> it made no difference.
> 
> I've had a co-worker look over my shoulder to make sure I'm not doing
> something insanely stupid, but if I am, he's not seeing it either.
> 
> The only thing I can think of, that I've not had the time to fully explore
> yet, is that one of dependency jar files in my application is at fault.
> Perhaps I'm on a wrong version of one of the dependencies and it's getting
> picked up, even when using the full velocity-dep-1.5.jar jar.  (I have a
> dependency on commons-collections, even outside of the use of Velocity).
> This page:
> http://velocity.apache.org/engine/devel/jar-dependencies.html
> lists the dependencies but doesn't give version numbers.  Are version
> numbers listed somewhere that I'm missing?
> 
> Thanks for your help.
> 
> Jeff
> 
> 
> 
> -----Original Message-----
> From: Will Glass-Husain [mailto:wglasshusain@gmail.com]
> Sent: Sunday, May 06, 2007 11:01 AM
> To: Velocity Users List
> Subject: Re: Template cache _kinda_ works?
> 
> 
> [my original note got rejected as spam.  removing the attachment, seeing if
> that helps]
> 
> ---------- Forwarded message ----------
> From: Will Glass-Husain <wglasshusain@gmail.com>
> Date: May 6, 2007 7:56 AM
> Subject: Re: Template cache _kinda_ works?
> To: Velocity Users List <user@velocity.apache.org>, "Bensman, Jeff [EESUS
> Non J&J]" <JBensma1@eesus.jnj.com>
> 
> Hi Jeff,
> 
> I built a small test servlet to check this and had no problems.  I used the
> StringWriter just as you described.  I displayed a file, changed it, and
> refreshed the page.  When I refreshed in less than 10 seconds it showed the
> old text.  When I refreshed after 10 seconds, it showed the new text.
> 
> How are you changing the file?  Obviously, the file timestamp has to change
> for Velocity to notice it is new.
> 
> Also - is this a web app?  Are you sure it's just not something silly like a
> browser cache of the page?
> 
> (Test code attached, though it'll probably get stripped by the list serv).
> 
> WILL
> 
> 
> On 5/4/07, Bensman, Jeff [EESUS Non J&J] < JBensma1@eesus.jnj.com> wrote:
>> I've got the Velocity 1.5 engine integrated into my application's code and
>> everything seemed to be going great.  But then, I noticed that template
>> caching is only _kinda_ working.
>>
>> I've stepped through the Velocity source code to verify that my template
>> object is correctly reloading when modified (I'm using
>> FileResourceLoader).
>> By verify, I mean that I can see that the ResourceLoader's isCachingOn()
>> is
>> correctly returning true and the class's modificationCheckInterval
>> reflects
>> my property setting (10 seconds).  And if I...
>>
>> - call Velocity.getTemplate(String name)
>> - run a merge( Context context, Writer writer) on the returned template
>> - go out to the file system and edit the template file (after waiting 10
>> seconds)
>> - and then re-run the Velocity.getTemplate()
>>
>> ...I see that the Template object I get from getTemplate() the second
>> time,
>> reflects the file system change I made (Yeah!), because its data property
>> is
>> holding my new stuff.  BUT, when I call merge on it, the StringWriter I
>> get
>> back reflects the old state of the template, before my change!
>>
>> Here's my code:
>>
>> public static String buildView(String templateName, Map templateData )
>> throws Exception {
>>     VelocityContext velocityContext = new VelocityContext(templateData);
>>     Template velocityTemplate = Velocity.getTemplate(templateName);
>>     StringWriter stringWriter = new StringWriter();
>>     velocityTemplate.merge( velocityContext, stringWriter );
>>     return stringWriter.toString();
>> }
>>
>> What am I missing?  I went back to Velocity 1.4 to make sure it wasn't
>> some
>> new bug in 1.5, but 1.4 behaves the same way.
>>
>> Thanks for any help,
>>
>> Jeff
>>
>>
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Mime
View raw message