You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Mark Hawkes <ha...@onetel.com> on 2005/04/18 17:16:19 UTC

VelocityServlet.mergeTemplate() - Efficient Writers?

The Developer Guide 
(http://jakarta.apache.org/velocity/developer-guide.html) says 
mergeTemplate() "uses a pool of very efficient Writer classes".

I'm maintaining a bunch of servlets that can't subclass VelocityServlet. 
Instead, they use Velocity in a "standalone" way, like this:

   // Velocity.init() already called elsewhere
   Context ctx   = new VelocityContext();
   Template tmpl = Velocity.getTemplate("foo.vm");
   tmpl.merge(ctx, someWriter);

Am I losing performance like this? Is it faster if I subclass 
VelocityServlet because I reap the benefits of mergeTemplate()?

Mark Hawkes
It Just Works Software
17 Colborne Street East, Suite 202
Orillia, Ontario L3V 1T4
1-705-326-4254


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: VelocityServlet.mergeTemplate() - Efficient Writers?

Posted by Simon Christian <si...@stoutstick.com>.
Hi Mark,

You're not losing performance because of that. The mergeTemplate method 
on Velocity (or VelocityEngine) basically does the same as you're doing 
i.e. getTemplate then merge with an added bit of error checking, ands 
adds optional encoding.

You might however be better off - in terms of maintainability - to 
switch to using VelocityEngine rather than the Singleton Velocity as it 
tends to play nicer.

- simon


Mark Hawkes wrote:
> The Developer Guide 
> (http://jakarta.apache.org/velocity/developer-guide.html) says 
> mergeTemplate() "uses a pool of very efficient Writer classes".
> 
> I'm maintaining a bunch of servlets that can't subclass VelocityServlet. 
> Instead, they use Velocity in a "standalone" way, like this:
> 
>   // Velocity.init() already called elsewhere
>   Context ctx   = new VelocityContext();
>   Template tmpl = Velocity.getTemplate("foo.vm");
>   tmpl.merge(ctx, someWriter);
> 
> Am I losing performance like this? Is it faster if I subclass 
> VelocityServlet because I reap the benefits of mergeTemplate()?
> 
> Mark Hawkes
> It Just Works Software
> 17 Colborne Street East, Suite 202
> Orillia, Ontario L3V 1T4
> 1-705-326-4254
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org