Hi,
I fixed this problem, so give it a try.
Sample code is:
import java.util.List;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class MultipleEngineStates {
private MultipleEngineStates() throws ScriptException {
System.out.println("[" + getClass().getName() + "]");
System.setProperty("org.jruby.embed.localcontext.scope",
“singlethread”);
ScriptEngineManager manager = new ScriptEngineManager();
List factories =
manager.getEngineFactories();
ScriptEngineFactory factory = null;
while (factories.iterator().hasNext()) {
factory = factories.iterator().next();
if (“ruby”.equals(factory.getLanguageName())) {
break;
}
}
ScriptEngine engine1 = factory.getScriptEngine();
ScriptEngine engine2 = factory.getScriptEngine();
engine1.put(“Value”, new String("engine1 "));
engine2.put(“Value”, new Double(-0.0149));
Object obj1 = engine1.eval(“puts $Value; $Value + 2010.to_s”);
Object obj2 = engine2.eval(“puts $Value; $Value + 2010”);
System.out.println(obj1 + ", " + obj2);
}
public static void main(String[] args) throws ScriptException {
new MultipleEngineStates();
}
}
This outputs:
engine1
-0.0149
engine1 2010, 2009.9851
Make sure, you are using singlethread or threadsafe model.
-Yoko
On Sun, Mar 7, 2010 at 3:59 PM, Yoko H. [email protected] wrote:
engine, Ruby runtime always works for you. All variable values must be
variable, even though you have multiple engine instances, the value
Thanks
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email