Spawn new JRuby interpreters from Jruby

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

On Mon, Oct 26, 2009 at 8:09 AM, Zachary C. [email protected]
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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs