Hello,

I’m currently dealing with a Java app using a Groovy DSL and I’m running into 
some PermGen problems. I'd like to use caching in order to avoid evaluating the 
scripts again ans again. However I'm struggling with the lack of documentation 
on this topic. 

Here's my situation. A Groovy DSL is received as String and passed on to a new 
GroovyShell instance like this :

GroovyShell shell = new 
GroovyShell(Thread.currentThread().getContextClassLoader(), binding);
Object result = shell.evaluate(sourceCodeAsString);

Basically we receive the same DSL until a newer version is pushed. The only 
difference between the calls is the binding. Each call is given its own shell, 
contextClassLoader and binding.

I do understand that each call to evaluate() will put the compiled script into 
the class loader. 

However until a notification of a newer version of the DSL is sent there's no 
need to recompile the same source over and over. It only makes the class loader 
bigger.

So my question is what are the best practices in order to :

- Cache the Groovy DSL until a newer version is detected (in a 
GroovyClassLoader ?)
- Remove the previous version from the cache and from the class loader

And also :

- Is it possible/acceptable to share a GroovyShell (or a pool of GroovyShell) 
among the different calls ? (thread safety issues, etc…)
- Same question for a GroovyClassLoader (as singleton)

Thanks in advance.

Damien

Reply via email to