You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Mike Curwen <gb...@gb-im.com> on 2003/06/27 18:16:17 UTC

Question regarding Singleton vs. Engine

>From the doc:
===================================================================
Singleton Model 

This is the legacy pattern, where there is only one instance of the
Velocity engine in the JVM (or web application, depending) that is
shared by all. This is very convenient as it allows localized
configuration and sharing of resources. For example, this is a very
appropriate model for use in a Servlet 2.2+ compliant web application as
each web application can have it's own instance of Velocity, allowing
that web application's servlet to share resources like templates, a
logger, etc. The singleton is accessable via the
org.apache.velocity.app.Velocity class, and and example of use : 
===================================================================
The example of use that follows is the same code that is in
org.apache.velocity.servlet.VelocityServlet
 
But shouldn't the first sentence read "one instance of the Velocity
engine per classloader" rather than "in the JVM" ?  Otherwise, how can
you have two different velocity web apps in Tomcat (same VM) using two
separate configurations? (different template paths).

I'm curious, because I'm wanting to use Velocity as a merging engine
*within* my web application that is velocity based.  I'm extending the
velocityservlet (yes I know, there's a tools thing I should be using)
for the web itself with certain template paths and parsers etc, etc.
But separate from this, I have a library class, a reusable "merging"
engine (ahem, a thin wrapper of Velocity) that I want to include within
the webapp.  And I wanted to make my classes use a singleton as well,
but it's template path is the system root, so it can merge from
anywhere, to anywhere.  But I'm wondering how my library classe's
singleton wouldn't conflict with my webapp's singleton (or for that
matter how webappA's singleton doesn't conflict with webappB's
singleton).


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