14 Jul 2004 12:21
Re: Reusing GroovyShell/GroovyClassLoader instance without the Binding
BTW a quick fix for your issue could be to use an LRUMap (or maybe WeakHashMap) where the key is the groovy source code as a String and the value is the compiled Class file. Then only compile a script if its not in the cache. Getting more clever and using File/URL objects to be the key and using lastModified() dates would help avoid keeping lots of big strings in RAM :) But this is pretty much what Sam's GroovyScriptEngine does 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... > > Best regards, > > Jesper > > James ------- http://radio.weblogs.com/0112098/
RSS Feed