Yes, that looks safe to me. As long as the ToolContext is nested behind another context, so it isn't changed by #set calls in the threads, you should be fine.
On Wed, Jan 18, 2012 at 2:16 AM, Christian Beutenmüller <christian.beutenmuel...@saxess.ag> wrote: > Hi folks, > > I'm currently embedding Velocity in some custom JSF Components roughly > based on the idea of Mathias Wessendorf as shown in > http://people.apache.org/~matzew/jsfvelocity.html. > Now I'd like to know if it's safe to reuse the ToolContext accross > requests and threads. > > Currently my setup code is: > > Singleton setup of VelocityEngine via Spring: > - Init VelocityEngine as Singleton > - Init ToolManager as Singleton, set VelocityEngine > - Get Tool Context from ToolManager > > Per Request Rendering: > - Create VelocityContext based on ToolContext and Parameter Map > - merge Template > > The code is shown below. > > Are there any threading/synchronisation Issues I am not aware of? > The documentation I've read so far, did basically tell, that chaininig > of VelocityContext instances should be ok in a multithread environment. > > Code: > > //Singleton setup: > public void setEngine(final VelocityEngine engine) { > this.engine = engine; > this.toolManager = new ToolManager(); > this.toolManager.setVelocityEngine(engine); > this.toolManager.setUserCanOverwriteTools(false); > this.toolContext = toolManager.createContext(); > } > > //per Request use: > public void merge(String template, ResponseWriter writer, Map<String, > Object> parameters) { > > final VelocityContext velocityContext = new > VelocityContext(parameters, toolContext); > engine.mergeTemplate(template, "UTF-8", velocityContext, writer); > } > > Greetings, > Christian > > > -- > > Christian Beutenmüller > saxess.ag > Springerstr. 15 > 04105 Leipzig > > Tel.: +49(341)218299-60 > Fax.: +49(341)218299-94 > Mail: christian.beutenmuel...@saxess.ag > Http: www.saxess.ag > > HRB 17905 (AG Leipzig) > Vorstand: Gerd Tautenhahn, Matthias Lehmann > Aufsichtsrat (Vors.): Holger Grentzebach > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org > For additional commands, e-mail: user-h...@velocity.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org