Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
2.4.10
-
None
Description
I am wondering if I can safely share an instance of GroovyScriptEngineImpl across threads when each thread has a different Bindings AND i need to use InvokeFunction.
I believe I need to call the eval method on the engine in every thread so as to establish the new context containing thread-specific Bindings. During the call to Eval, the functions in my script are turned into some 'method closure' objects containing (between other things) the thread-specific Bindings. However, those 'method closure' are kept in a map that is global to the script engine (this map is called 'globalClosures').
I think that the "method closure" is added to the map twice, once for each thread, under the same key (the name of the function) and whatever thread updates the map last is the one that imposes its Bindings to the function.
When later, the function is invoked in each thread, the same Bindings is used.
I have attached a small sample of code demonstrating the issue.
The output is sometimes:
The task that should return 42 returned : 43
The task that should return 43 returned : 43
and sometimes:
The task that should return 42 returned : 42
The task that should return 43 returned : 42
depending on what thread updates the globalClosures last.