Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rhino in Mutlithreading Environment

49 views
Skip to first unread message

Roland Schuller

unread,
May 28, 2010, 1:07:32 AM5/28/10
to
Hi to all!

Like the Header said, im unsing Rhino in an multithreading environment
and it woks. Except sometimes. And here is the problem.

I have one Javascript file with some functions.
Later according to Events in Java i call these functions.

First I load the Javascript

public void doCode(String code)
{
Context cxl = Context.enter();
cxl.setGeneratingDebug(false);
cxl.setGeneratingSource(false);
cxl.setOptimizationLevel(9);

code="Packages.java\n"+code;
code="Packages.at\n"+code;

script=cxl.compileString(code, "InterpreterCode", 1, null);
script.exec(cxl, scope);
Context.exit();
}


Then in an Runnable called by an Executor i call these lines.

public String eval(final String code)
{

return (String)ContextFactory.getGlobal().call(new
ContextAction() {
public Object run(Context cx) {

Scriptable newScope = cx.newObject(scope);
newScope.setPrototype(scope);
newScope.setParentScope(null);

Object o=cx.evaluateString(newScope, code, "Manual Exec",
1, null);
String out = Context.toString(o);
return out;
}
});

These lines can be called parallel and in different Threads.
First I had the problem that i idnt put 'var' in front of may JS
variables, which turned out to make a complete mess. But I corrected
this issue.

Now sometimes it happens that the Code is called, 'eval ("start()") but
nothing happens.

Is it possible to get an Information from Rhino which Line it is
currently processing?

Have done something completely wrong?

Using 1.7R2 and JDK 1.6.20 both Windows and Linux.


Thanx for your help!

Roland

Roland Schuller

unread,
May 31, 2010, 4:59:02 AM5/31/10
to
Sorry for bothering You!

found the Error:
I had to put the


Object o=cx.evaluateString(newScope, code, "Manual Exec", 1, null);

in an try-Except.

Now I get great errormessages (from multithreading problens in my code)

Thanx anyway!

0 new messages