Spawn new JRuby interpreters from Jruby

View: New views
2 Messages — Rating Filter:   Alert me  

Spawn new JRuby interpreters from Jruby

by Zach Carter-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is it possible to spawn another JRuby interpreter from within JRuby?
I'm looking to use this as an alternative to forking, and to avoid
unavoidable race conditions involved with using threads. I'm sure you
can create multiple JRuby runtimes from Java, but I couldn't find much
documentation on that either.

Thanks.

--
Zach Carter
http://zach.carter.name

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Spawn new JRuby interpreters from Jruby

by Nick Sieger-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Oct 26, 2009 at 8:09 AM, Zachary Carter <zack.carter@...> wrote:
> Is it possible to spawn another JRuby interpreter from within JRuby?
> I'm looking to use this as an alternative to forking, and to avoid
> unavoidable race conditions involved with using threads. I'm sure you
> can create multiple JRuby runtimes from Java, but I couldn't find much
> documentation on that either.

Sure, you should be able to do it. There are several ways:

- Default behavior when you do `system("script.rb")` is to launch a
new JRuby runtime in the same JVM.
- You can use normal Java integration to call into javax.script (1.3
and earlier) or the new org.jruby.embed API (coming in 1.4).
- There is also early work on a MVM (multiple virtual machine) API
that would probably match your needs best. The API includes the
ability to send messages back and forth between sub-vms. Example code
here: http://github.com/jruby/jruby/blob/master/samples/mvm.rb (Note,
I tried the code on trunk and it doesn't appear to be working).

/Nick

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email