Subj : Re: Rhino and multithreading To : Barre Dijkstra From : user@domain.invalid Date : Wed Dec 31 1969 04:00 pm The Rhino shell has a spawn() function that runs a script in another thread. It returns the java thread object which you can then join(). var x; var t = spawn(function() { x = someTimeConsumingFunction(); }); var y = 12; // ... t.join(); var z = x + y; Barre Dijkstra wrote: > Greetings, > > I am currently banging my head to the wall due to the following problem: > I'm looking at rhino for an ecmascript implementation in java. All fine and > well, until you start thinking about optimization and threading. > > What I'm trying to accomplish is that when some script calls certain > functions (implemented in an object that extends ScriptableObject that has > been added to the applicable contexts) that a new thread is forked for > optimization resons (for example, you don't want to halt your whole program > when talking to some time consuming process on another machine over > sockets). For example: > > var x = someTimeConsumingFunction(); > var y = 12; > var z = x + y; > > How would the interpreter know that someTimeConsumingFunction() is done > processing since there are no means to place a lock on either x or > timeConsumingFunction(); > > In other words, has anyone had any experience in synchronization of > javascript using rhino, or does anyone know any other javascript engine (in > java) that does support threading? > > Thanks, > > Barre > > .