velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <>
Subject Re: How to make #for thread-safe?
Date Fri, 07 Apr 2006 22:44:47 GMT
In a web application, thread-safety is only a concern if your context
objects are used in the session or application scopes.

If you are concerned about thread safety with the context, then i
would suspect that either you are trying to use a context or context
object in an inappropriate scope or else are needlessly worrying.

Each servlet request is just one thread in a normal web application. 
So for each request, you should probably be creating a new
VelocityContext and new/different instances of any mutable classes
into that context.  This is the standard practice for any view
technology (JSP/Velocity/Freemarker/etc).

On 4/7/06, David P <> wrote:
> Some archive msgs like this one point out that
> VelocityContext is not thread-safe:
> I have put some objects in my context that could be
> modified by other threads.  I can make these accesses
> thread-safe when using #set and #if, but I can't think
> of a way to protect containers when used by #for.  For
> example, another thread might remove an element from a
> container in the context while #for is iterating over
> it. Synchronizing the iterator method of the container
> wouldn't provide any protection. And putting a big
> synchronize block inside every servlet in the app,
> blocking on a shared object, wouldn't work because
> there's no way to get the Velocity template to wait on
> the same lock...right?
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message