velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@optonline.net>
Subject Re: Thread safety
Date Mon, 01 Oct 2001 22:44:42 GMT
On 10/1/01 5:02 PM, "David Esposito" <esposito@newnetco.com> wrote:

> Is there something fancy that goes on with the Context during the merge()
> that would make it non-thread-safe? Or is it just concern over the fact that
> #set() operations will change the content of the Context? (which isn't
> thread safe)

There is a fancy-thing going on - the 'context local' caching of
introspection info.  The VC learns as it travels around the AST.  Since
nothing requires you to put the same objects into the context for a given
reference for a given template, you could do some harm...  That's where the
risk is.

And be careful that this doesn't lead to misinformation - it's only with the
VelocityContext, not the Context in general.  VC has the context local cache
built in, so that you can reuse it for for efficiency.  Just making your own
Context and passing that in will be fine.  Vel takes care of it...

> 
> I haven't stress tested the hell out of it but I have a "default" context
> (with a bunch of global variables, tools, etc...) that I nest inside of the
> context that is created during each request ...
> 
> VelocityContext ctx = new VelocityContext(defaultContext);
> 
> is that safe?

Yes - because the outer context picks up the goo, so the inner stays clean.

geir
 
>> -----Original Message-----
>> From: Geir Magnusson Jr. [mailto:geirm@optonline.net]
>> Sent: Monday, October 01, 2001 6:00 AM
>> To: velocity-user@jakarta.apache.org
>> Subject: Re: Thread safety
>> 
>> 
>> On 10/1/01 4:24 AM, "Bojan Smojver" <bojan@binarix.com> wrote:
>> 
>>> Are Template.merge() and VelocityEngine.getTemplate() thread safe?
>>> 
>>> Bojan
>> 
>> merge() is as long as you don't share a VelocityContext across
>> simultaneous
>> threads.
>> 
>> getTemplate() should be as well.
>> 
>> Er, why?  Problems?
>> 
>> --
>> Geir Magnusson Jr.     geirm@optonline.net
>> System and Software Consulting
>> "Whoever would overthrow the liberty of a nation must begin by
>> subduing the
>> freeness of speech." - Benjamin Franklin
>> 
>> 
> 

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
"Whoever would overthrow the liberty of a nation must begin by subduing the
freeness of speech." - Benjamin Franklin



Mime
View raw message