org.jruby.internal.runtime
Class ThreadService

java.lang.Object
  extended by org.jruby.internal.runtime.ThreadService

public class ThreadService
extends java.lang.Object


Nested Class Summary
static class ThreadService.Event
           
 
Constructor Summary
ThreadService(Ruby runtime)
           
 
Method Summary
 void associateThread(java.lang.Object threadOrFuture, RubyThread rubyThread)
           
 void deliverEvent(ThreadService.Event event)
           
 void disposeCurrentThread()
           
 void dissociateThread(java.lang.Object threadOrFuture)
           
 RubyThread[] getActiveRubyThreads()
           
 boolean getCritical()
           
 ThreadContext getCurrentContext()
          In order to provide an appropriate execution context for a given thread, we store ThreadContext instances in a threadlocal.
 RubyThread getMainThread()
           
 java.lang.ThreadGroup getRubyThreadGroup()
           
 java.util.Map getRubyThreadMap()
           
 ThreadContext getThreadContextForThread(RubyThread thread)
           
 ThreadContext registerNewThread(RubyThread thread)
           
 void setCritical(boolean critical)
           
 void setMainThread(java.lang.Thread thread, RubyThread rubyThread)
           
 void unregisterThread(RubyThread thread)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadService

public ThreadService(Ruby runtime)
Method Detail

disposeCurrentThread

public void disposeCurrentThread()

getCurrentContext

public ThreadContext getCurrentContext()
In order to provide an appropriate execution context for a given thread, we store ThreadContext instances in a threadlocal. This method is a utility to get at that threadlocal context from anywhere in the program it may not be immediately available. This method should be used sparingly, and if it is possible to pass ThreadContext on the argument list, it is preferable. Description of behavior The threadlocal does not actually contain the ThreadContext directly; instead, it contains a SoftReference that holds the ThreadContext. This is to allow new threads to enter the system and execute Ruby code with a valid context, but still allow that context to garbage collect if the thread stays alive much longer. We use SoftReference here because WeakReference is collected too quickly, resulting in very expensive ThreadContext churn (and this originally lead to JRUBY-2261's leak of adopted RubyThread instances).

Returns:
The ThreadContext instance for the current thread, or a new one if none has previously been created or the old ThreadContext has been collected.

getMainThread

public RubyThread getMainThread()

setMainThread

public void setMainThread(java.lang.Thread thread,
                          RubyThread rubyThread)

getActiveRubyThreads

public RubyThread[] getActiveRubyThreads()

getRubyThreadMap

public java.util.Map getRubyThreadMap()

getRubyThreadGroup

public java.lang.ThreadGroup getRubyThreadGroup()

getThreadContextForThread

public ThreadContext getThreadContextForThread(RubyThread thread)

registerNewThread

public ThreadContext registerNewThread(RubyThread thread)

associateThread

public void associateThread(java.lang.Object threadOrFuture,
                            RubyThread rubyThread)

dissociateThread

public void dissociateThread(java.lang.Object threadOrFuture)

unregisterThread

public void unregisterThread(RubyThread thread)

setCritical

public void setCritical(boolean critical)

getCritical

public boolean getCritical()

deliverEvent

public void deliverEvent(ThreadService.Event event)


Copyright © 2002-2007 JRuby Team. All Rights Reserved.