<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Nick Sieger: Process, Thread, Whatever</title>
  <subtitle type="html">do what you love</subtitle>
  <id>tag:blog.nicksieger.com,2005:Typo</id>
  <generator uri="http://www.typosphere.org" version="4.0">Typo</generator>
  <link rel="self" type="application/atom+xml" href="http://blog.nicksieger.com/xml/atom10/article/224/feed.xml"/>
  <link rel="alternate" type="text/html" href="http://blog.nicksieger.com/articles/2007/03/16/process-thread-whatever"/>
  <updated>2007-08-31T17:14:15+00:00</updated>
  <entry>
    <author>
      <name>Nick Sieger</name>
    </author>
    <id>urn:uuid:aedaaefd-543f-496b-ad12-5d0027b233ce</id>
    <published>2007-03-16T04:18:00+00:00</published>
    <updated>2007-08-31T17:14:15+00:00</updated>
    <title>Process, Thread, Whatever</title>
    <link rel="alternate" type="text/html" href="http://blog.nicksieger.com/articles/2007/03/16/process-thread-whatever"/>
    <category term="jruby" scheme="http://blog.nicksieger.com/articles/tag/jruby"/>
    <content type="html">&lt;p&gt;While cleaning up the subprocess launching code in JRuby recently, I pulled a fast one.  See, JRuby has this little trick we call an in-process script that allows launching of a separate JRuby runtime in the same process.  Basically, we look for the command-line passed to &lt;code&gt;Kernel#system&lt;/code&gt; or &lt;code&gt;Kernel#backtick&lt;/code&gt;, and if the program name contains &amp;#8220;ruby&amp;#8221; or ends in &amp;#8220;.rb&amp;#8221;, we assume the caller wants to launch another JRuby interpreter and launch the command in the same process instead of spawning a new one.  Set aside for a moment the question of whether this is &amp;#8220;the right thing&amp;#8221; to do.&lt;/p&gt;

&lt;p&gt;In my desire to dry up this code a bit, but also to extend the same behavior for &lt;code&gt;IO.popen&lt;/code&gt;, I needed the in-process script to behave like a real process.  So hey, why not extend &lt;code&gt;java.lang.Process&lt;/code&gt;?  The details are in the &lt;a href="http://svn.jruby.codehaus.org/browse/jruby/trunk/jruby/src/org/jruby/util/ShellLauncher.java"&gt;ShellLauncher&lt;/a&gt; code, but it turns out, oddly enough, this actually works.&lt;/p&gt;

&lt;p&gt;I think this points out an interesting feature of JRuby &amp;#8211; that it&amp;#8217;s process-agnostic.  You can map JRuby runtimes M:N with processes in any combination you like.  In fact, this is what&amp;#8217;s currently being done with the &lt;a href="http://www.headius.com/jrubywiki/index.php/Rails_Integration"&gt;Rails Integration&lt;/a&gt; (Rails-in-a-war-file) code &amp;#8211; a pool of JRuby runtimes preloaded with Rails are used to run the Rails application from a Java servlet.  Robert Egglestone&amp;#8217;s been doing some great work with Rails Integration and the possibilities are only starting to reveal themselves.&lt;/p&gt;</content>
  </entry>
</feed>
