velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niall Gallagher <>
Subject Re: Synchronizing a Context
Date Tue, 20 Jan 2004 14:45:29 GMT

>> Exactly, so if I did somthing like  
>> servletContext.setAttribute("sharedContext", mySharedContext) and 
>> multiple independant servlets required access to the context to 
>> render a template, then there would be a problem with the AST caching 
>> and also setting and getting from the least this is what 
>> I have understood of the AbstractContext.
> ... but if the context has just a 'get' method and doesn't change 
> along the processing fine ... but if you have a getter and a setter 
> both have to be synchronized, otherwise a getter could read the 
> context while a setter is updating it, isn't it?

I concerns are slightly different...synchronization of the Context.get 
and Context.put were not problems..I could simply synchronize all the 
methods of the Context interface and use it to set and get 
properties....However what if this happened....what would happen with 
the unsynchronized icachePut and icacheGet methods ?

servlet in thread 1

template1.merge(out2, mySharedContext);

servlet in thread 2

temjplate2.merge(out2, mySharedContext);

I think you are making a point for a context being a container of 
properties (perhaps wrapped within a local VelocityContext), in this 
case simply retrieving data without synchronization is only 
worries, which I am far too lazy to explore, are the Velocity internals, 
I dont know what the AST is caching nor do I want to know. In terms of 
the simple context usage I would simply have cut and pasted 
VelocityContext into a file and replaced the HashMap used with a 
Hashtable....apparently this will not any case I have 
decided that extending the AbstractContext is not a good idea for was not intended for use in this environment....Instead I have 
just implemented the Context methods around a Hashtable...... which is 
similar to what you have suggested ;)


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

View raw message