0

我有一些代码创建了一个 Groovy CompilerConfiguration,其中包含使用 ImportCustomizer 添加的一堆隐式导入。我想知道在多个 GroovyClassLoaders 或 GroovyShell 中重用相同的 CompilerConfiguration 对象是否安全。我在 GroovyClassLoader 或 GroovyShell 中看不到任何会改变传入的 CompilerConfiguration 的代码,因此它可能是安全的。

4

1 回答 1

1

As long as you're stick with ImportCustomizer, it is probably safe, but neither compilation customizers nor the compiler configurations are designed to be thread safe, so it's probably better to use distinct configuration objects. This is in general true for any class in the compilation process: it's not thread safe.

I can easily imagine a situation where you create a CompilerConfiguration, pass it to multiple GroovyShell instances and add customizers in different threads.

So I would say, unless you have a very good reason to share the same configuration (and I don't really see one :)), go the safe way and use distinct objects.

于 2012-07-13T16:19:02.987 回答