# Threads in JRuby vs standard Ruby

**URL:** <https://www.ruby-forum.com/t/threads-in-jruby-vs-standard-ruby/141309>\
**Category:** Ruby\
**Created:** [June 24, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/threads-in-jruby-vs-standard-ruby/141309 "2008-06-24T16:26:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 24, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/threads-in-jruby-vs-standard-ruby/141309/1 "2008-06-24T16:26:22Z")

</div>

Hello guys,

This is the first time I am working with threads and so far it gave me a  
good result in the speed of my code, using Ruby 1.8.6 in the native Mac  
OS  
X distribution. By I read in the book “The Ruby P.ming language”  
that  
the threads in the standard “C” Ruby 1.8.6 are not real OS threads and  
they all share the same main Ruby thread. I have read also that JRuby  
implements real OS threads.

My code triggers more than 200 threads each of them with one private  
connection to a MySQL database.

Would it be a real advantage to use JRuby in this scenario?

Thanks,

Guillermo

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 24, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/threads-in-jruby-vs-standard-ruby/141309/2 "2008-06-24T16:32:50Z")

</div>

El Martes, 24 de Junio de 2008, removed\_email\_address@domain.invalid escribiÃ³:

> Hello guys,
> 
> This is the first time I am working with threads and so far it gave me a  
> good result in the speed of my code, using Ruby 1.8.6 in the native Mac OS  
> X distribution. By I read in the book “The Ruby P.ming language” that  
> the threads in the standard “C” Ruby 1.8.6 are not real OS threads and  
> they all share the same main Ruby thread. I have read also that JRuby  
> implements real OS threads.

Read this good document about Ruby threading:  
[The Futures of Ruby Threading](http://www.infoq.com/news/2007/05/ruby-threading-futures)

> My code triggers more than 200 threads each of them with one private  
> connection to a MySQL database.
> 
> Would it be a real advantage to use JRuby in this scenario?

Well, Ruby threads are “green” threads, this is: they only exist into  
the Ruby  
process but not for the OS so all the threads runned into a Ruby process  
share the same processor (you get not advantage of a multiprocessor  
computer).

JRuby uses the Java virtual machine, and that uses real OS threads, but  
that’s  
all I know 🙂

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 24, 2008, 4:59pm UTC](https://www.ruby-forum.com/t/threads-in-jruby-vs-standard-ruby/141309/3 "2008-06-24T16:59:15Z")

</div>

On Tue, Jun 24, 2008 at 6:29 PM, IÃ±aki Baz C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Read this good document about Ruby threading:  
> share the same processor (you get not advantage of a multiprocessor

Same problem. But i solve it as DRb + fork.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 24, 2008, 5:13pm UTC](https://www.ruby-forum.com/t/threads-in-jruby-vs-standard-ruby/141309/4 "2008-06-24T17:13:21Z")

</div>

El Martes, 24 de Junio de 2008, Zhukov P. escribiÃ³:

> Same problem. But i solve it as DRb + fork.

Could you please give a tip of your solution using Drb + fork?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 24, 2008, 5:29pm UTC](https://www.ruby-forum.com/t/threads-in-jruby-vs-standard-ruby/141309/5 "2008-06-24T17:29:15Z")

</div>

core app starts DRb server with self as front object. then, i fork  
‘plugins’ that connect to core app and “register” youself in core’s  
@plugin list.

Modified signal system provide communication between processes.

if you interested:  
[Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/rudcpp/source/browse/trunk/core.rb)#core class  
[Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/rudcpp/source/browse/trunk/plugins/plugin.rb)  
#all plugins should be based on it  
[Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/rudcpp/source/browse/trunk/lib/signal.rb)  
#modified signal system

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 25, 2008, 12:10am UTC](https://www.ruby-forum.com/t/threads-in-jruby-vs-standard-ruby/141309/6 "2008-06-25T00:10:44Z")

</div>

removed\_email\_address@domain.invalid wrote:

> connection to a MySQL database.
> 
> Would it be a real advantage to use JRuby in this scenario?

If you would like your app to take advantage of multiple cores without  
the complexity of cross-process communication, then JRuby would probably  
be a great choice.

- Charlie

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 24, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/threads-in-jruby-vs-standard-ruby/141309/7 "2008-06-24T17:32:46Z")

</div>

El Martes, 24 de Junio de 2008, Zhukov P. escribiÃ³:

> [Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/rudcpp/source/browse/trunk/lib/signal.rb)  
> #modified signal system

Thanks a lot, it seems interesting.
