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:39:49 GMT
On 10/1/01 4:58 PM, "Nick Bauman" <nick@cortexity.com> wrote:

>> 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.
> 
> Which means the answer is "no" ;)

No, it means the answer is

"merge() is as long as you don't share a VelocityContext across simultaneous
threads."

If you make up your own, threadsafe Context, then yes, merge() is safe.
It's VelocityContext that isn't

Lets face it - you don't want to have one thread using a VC in merge() while
another is modifying data.  merge() won't guarantee anything about the VC.

> 
> You have really only 2 choices for the web:
> 
> a) Create a new VelocityContext for each http request
> b) Pool VelocityContexts and recycle them. Since they already implement
> clone() very nicely, this should be easy.

Yep.  And making a VC with each request isn't that expensive.

Another option is to stuff the VC into the session for the user....

> 
> There is one more choice, but it's not a real one:
> 
> c) serialize access to the context --  not really an option on the web

No, that's not good.


Geir

 
> 
>> 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
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



Mime
View raw message