I have code like following
https://gist.github.com/3306301
I'm caching Class object returned from GroovyClassLoader and calling
InvokerHelper.createScript(scriptclass, binding).run()
InvokerHelper.createScript(scriptclass, binding) can be called from
multiple threads for different binding instances but same scriptclass,
from my tests it seems its threadsafe.
I just want to confirm with experts if I'm not missing anything.
Thanks for help.
// code
//
public class Script {
private static final GroovyClassLoader GCL = new
GroovyClassLoader(); // XXX GroovyClassLoader is threadsafe ?
private final Class scriptClass;
public Script(String script) throws CompilationFailedException {
scriptClass = GCL.parseClass(script);
}
public Object invoke(Binding binding) {
groovy.lang.Script gscript =
InvokerHelper.createScript(scriptClass, binding); // XXX
InvokerHelper.createScript is threadsafe?
return gscript.run();
}
public static void main(String[] args) throws Exception {
String my_groovy_script_as_string = "(foo, bar) = [bar, foo];";
final Script script = new Script(my_groovy_script_as_string);
Runnable task = new Runnable() {
public void run() {
Binding binding = new Binding();
binding.setVariable("foo", UUID.randomUUID().toString());
binding.setVariable("bar", UUID.randomUUID().toString());
script.invoke(binding);
}
};
Thread[] pool = new Thread[] {new Thread(task), new
Thread(task), new Thread(task)};
for (Thread t : pool) t.start();
for (Thread t : pool) t.join();
}
}
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email