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:46:19 GMT

>Well, what i'm actually referring to is creating a my defaultContext inside
>of my Servlet init() method. Which, i believe (but wouldn't swear to without
>reading the spec), is guaranteed to execute before any of attempt to "use"
>the context via the doPost/doGet  ... The objects I stick in there are, as
>you suggest, immutable ... examples include:
>
>- list of states
>- list of countries
>- "tool" objects that contain formatting functions (static methods) ...

It depends what hat you're wearing.  With my "Professor of Computer 
Science" hat (which I don't own, but borrow from friends when they're not 
looking), this is probably not guaranteed to be thread safe, as it is 
possible for the servlet container to have created multiple threads for 
running servlet requests, and have the init() execute in one and then the 
servlet used by the other.  On the other hand, putting my "Real World 
Programmer" hat on (mine, and well used) I would expect that there's enough 
other synchronization going on in the servlet container that this will 
probably not cause problems.

>so it sounds like, in my particular case, sharing a velocity context across
>threads is safe ..

Sharing the default context is, but sharing the per-request context will 
NOT be, unless you're either externally synchronizing, or not ever putting 
anything in the per-request context.



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

http://www.quiotix.com


Mime
View raw message