Re: Question on TemplateCache synchronization

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Is this just a coincidence that you ask it now? Because, the reworked
caching system was committed only like days ago. It's much more
multi-core friendly now. Grab the HEAD of the 2.3 branch from
https://freemarker.svn.sourceforge.net/svnroot/freemarker/branches/2.3/freemarker
and give it a try. (I wanted to say to grab the latest nightly build
jar, but it seems that service is down at the moment.)

Thursday, April 10, 2008, 12:19:06 AM, Bruce Ritchie wrote:

> I'm currently analyzing a thread dump from a production environment
> where I have 100 threads in waiting on the CacheStorage lock in
> TemplateCache:
>
> at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:246)
> - waiting to lock <0x27445a20> (a freemarker.cache.MruCacheStorage)
> at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:229)
> at
> freemarker.template.Configuration.getTemplate(Configuration.java:487)
> at
> freemarker.template.Configuration.getTemplate(Configuration.java:452)
>
> and one thread actually holding the lock:
>
> at java.lang.Throwable.fillInStackTrace(Native Method)
> at java.lang.Throwable.<init>(Throwable.java:196)
> at java.lang.Exception.<init>(Exception.java:41)
> at javax.naming.NamingException.<init>(NamingException.java:109)
> at
> org.apache.naming.resources.FileDirContext.lookup(FileDirContext.java:208)
> at
> org.apache.naming.resources.ProxyDirContext.lookup(ProxyDirContext.java:294)
> at
> org.apache.catalina.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:1891)
> at
> org.apache.catalina.loader.WebappClassLoader.findResource(WebappClassLoader.java:934)
> at
> org.apache.catalina.loader.WebappClassLoader.getResource(WebappClassLoader.java:1069)
> at
> com.jivesoftware.community.util.ChainingClassLoader.getResource(ChainingClassLoader.java:91)
> at
> com.jivesoftware.community.web.struts.JiveClassTemplateLoader.getURL(JiveClassTemplateLoader.java:27)
> at
> freemarker.cache.URLTemplateLoader.findTemplateSource(URLTemplateLoader.java:75)
> at
> freemarker.cache.MultiTemplateLoader.findTemplateSource(MultiTemplateLoader.java:111)
> at
> freemarker.cache.TemplateCache.acquireTemplateSource(TemplateCache.java:520)
> at
> freemarker.cache.TemplateCache.findTemplateSource(TemplateCache.java:510)
> at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:315)
> - locked <0x27445a20> (a freemarker.cache.MruCacheStorage)
> at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:229)
> at
> freemarker.template.Configuration.getTemplate(Configuration.java:487)
> at
> freemarker.template.Configuration.getTemplate(Configuration.java:452)
>
>
> Is there really a good reason for synchronizing on the CacheStorage?
>>From my reading of the code there might be a small race between
> storage.get()l and storage.remove() but I'm not sure it's really worth
> synchronizing for. Am I wrong in this statement? If so, can someone
> suggest an alternate approach that doesn't require synchronization? In
> production we set the templateUpdateDelay to Integer.MAX_VALUE so
> basically we should never have to worry about the template changing or
> being removed after it's loaded.
>
>
> Regards,
>
> Bruce Ritchie
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2. 
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user

-- 
Best regards,
 Daniel Dekany


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.