velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leon Messerschmidt <l...@opticode.co.za>
Subject Template Chaching
Date Tue, 29 Aug 2000 12:57:03 GMT
Hi,

At the moment the template caching in FileTemplateLoader.java looks
something like this:

            Template template = new Template( file.getAbsolutePath() );
            template.preParse();

            if ( useCache )
            {
                synchronized(lock)
                {
                    cache.put( name, template );
                }
            }

Suppose two threads asks for the same template almost simultaneously then
both will fail to find the template in the cache.  Both will then create the
template (i.e. load the file and preParse it).  They will then proceed to
write identical objects to the cache.  The last one overriding the value of
the first one.  AFAIK Hashtables are thread save so synchronized(lock)
serves no purpose.

If we need locking we need a more sophisticated mechanism - see the Turbine
Mailing archives for a discussion on TurbineChacingService.  Otherwise we
can just drop the synchronized(lock) and get not have the performance
penalty.

~ Leon



Mime
View raw message