velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Goetz <br...@quiotix.com>
Subject Re: Thread safety
Date Mon, 01 Oct 2001 21:23:31 GMT

> > merge() is as long as you don't share a VelocityContext across
> > simultaneous threads.
>
>Which means the answer is "no" ;)

Actually, I would say that this characterization is true but 
misleading.  The VelocityContext operations are explicitly not thread-safe, 
but merge() and friends are (according to Geir, I've not checked) 
thread-safe except to the extent that they use the VC.  While according to 
a dictionary definition, you might characterize this as being not 
thread-safe, in reality, as long as you are using VC properly (not sharing 
it across threads), then merge() and friends do not require additional 
synchronization.

>  b) Pool VelocityContexts and recycle them. Since they already implement
>clone() very nicely, this should be easy.

This is what WM does.  The Broker creates a Context at startup, and 
populates a pool using clone().  Alternately, you could use ThreadLocal to 
keep one around for each thread.



--
Brian Goetz
Quiotix Corporation
brian@quiotix.com           Tel: 650-843-1300            Fax: 650-324-8032

http://www.quiotix.com


Mime
View raw message