velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <nbu...@gmail.com>
Subject Re: Problem with static classes and chained contexts
Date Mon, 11 Jun 2012 17:42:32 GMT
Yeah, i'd call that a bug.  Would you mind filing it in JIRA?  As for
performance gains, i would operate under the assumption that the gains
are small.  Yes, you cut down on map puts and short-term memory churn,
but each reference insertion has an extra lookup step now.  Unless the
default context objects are significant in terms of init-time or
memory usage (which does not appear to be the case from your example,
i would expect the return to be negligible.

On Thu, Jun 7, 2012 at 7:53 AM, Steve O'Hara
<sohara@pivotal-solutions.co.uk> wrote:
> Hi All,
>
> Has anyone else noticed a problem with chained contexts and static classes?
> As a performance improvement, I decided to put all our static context objects into a
context that would be the basis of all new contexts e.g.
>
>    private static Context chainedContext;
>    static {
>        chainedContext = Z_getDefaultVelocityContext();
>    }
>
>    private static Context Z_getDefaultVelocityContext() {
>        Context context = new VelocityContext();
>        context.put("TmpDir", Common.getTemporaryDirectory());
>        context.put("math", new MathTool());
>        context.put("number", new NumberTool());
>        context.put("sort", new SortTool());
>        context.put("LSQUARE_CHAR", '[');
>        context.put("RSQUARE_CHAR", ']');
>        context.put("LCURLY_CHAR", '{');
>        context.put("RCURLY_CHAR", '}');
>        context.put("DOT_CHAR", '.');
>        context.put("NEWLINE", '\n');
>        context.put("HASH", '#');
>        context.put("DOLLAR", '$');
>        context.put("DQUOTE", '"');
>        context.put("Utils", Common.class);
>        return context;
>    }
>
>    public static Context getVelocityContext(boolean runtimeMode) {
>        Context context = new VelocityContext(chainedContext);
>        context.put("Context", context);
>        return context;
>    }
>
> The problem is that in this configuration, $Utils is not available in the scripts.
> All the other instantiated objects are OK.  Works fine of course if the static class
is added to each outer context.
>
> I guess it's a bug but actually am I really going to gain much performance with this
technique anyway?
>
> Cheers
> Steve
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>

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


Mime
View raw message