On Mon, Mar 15, 2010 at 10:59 AM, Budyanto H.
[email protected] wrote:
What is really the difference between “singlethread” and “threadsafe”
Context Instance Type?
Threadsafe uses ThreadLocal to avoid race condition, but singlethread
does nothing. Singlethread is not thread safe. This model is based on
the assumption that only one thread works behind a script engine. In
some cases, singlethread is enough, while threadsafe is necessary on
other cases such as J2EE.
Does this affect the thread safety of the ScriptEngine’s eval() method
or invokeFunction() or both?
It depends on your case. Please see the thread that engine instance is
created on and the thread that those methods are executed on. If
exactly the same thread will be used always in both, singlethread is
Examples of the wiki page,
help you to understand the difference of local context models.
Unrelated question. Does invokeFunction actually parses the script
again? Or does parsing only occur once during the eval() call?
No. invokeFunction() method just calls Ruby methods. If you eval()
once, you don’t need to eval() anymore. However, eval() and
invokeFunction() must be done on the same thread. This is because Ruby
runtime memorizes the evaluated Ruby methods.
To unsubscribe from this list, please visit: