jastrachan | 14 Jul 08:27 2004
Picon

Re: Reusing GroovyShell/GroovyClassLoader instance without the Binding


On 14 Jul 2004, at 05:49, Jesper Kamstrup Linnet wrote:

> Hi,
>
> I have a situation where I have quite a few script sniplets embedded 
> in an
> XML document. Once loaded, the scripts don't change, thus eliminating 
> the
> need for recompiling. The scripts are used in a J2EE application and 
> may
> thus be run by multiple threads.
>
> I'd like to use a GroovyShell for the embedding in my Java code. My 
> question
> is: Is it possible to avoid having to reparse the scripts by keeping 
> the
> GroovyClassLoader instance (sharing it among the threads) but 
> replacing the
> Binding instance on each use. As the API on GroovyShell is now, I see 
> no
> such possibility. There are constructors to create a GroovyShell with a
> classloader (parent) and with or without a Binding, but since Groovy 
> parses
> the class with the topmost ClassLoader, as I see it there's no way of
> escaping the reparsing (which takes quite some time in my case).
>
> Currently, I've just copied a few methods from GroovyShell into my own 
> code
> and interact directly with GroovyClassLoader.parseClass, but I'd 
> rather be
> really Groovy...

:)

Totally agreed. We need to sort this out ASAP.

For the Groovlets work, Sam created a handy class which does this & 
auto-detects when scripts change & so things need to be recompiled...

http://groovy.codehaus.org/apidocs/groovy/util/GroovyScriptEngine.html

Maybe this class, or some wrapper facade of it could be useful? We 
should maybe figure out how to integrate this class into GroovyShell so 
it all happens under the covers

James
-------
http://radio.weblogs.com/0112098/


Gmane