org.jruby
Class RubyThread

java.lang.Object
  extended by org.jruby.RubyObject
      extended by org.jruby.RubyThread
All Implemented Interfaces:
java.lang.Cloneable, IRubyObject

public class RubyThread
extends RubyObject

Implementation of Ruby's Thread class. Each Ruby thread is mapped to an underlying Java Virtual Machine thread.

Thread encapsulates the behavior of a thread of execution, including the main thread of the Ruby script. In the descriptions that follow, the parameter aSymbol refers to a symbol, which is either a quoted string or a Symbol (such as :name). Note: For CVS history, see ThreadClass.java.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.Finalizer
 
Field Summary
 java.lang.Object killLock
           
 ReentrantLock lock
           
 java.lang.Object stopLock
           
 
Fields inherited from class org.jruby.RubyObject
instanceVariables, isTrue, metaClass, NEVER, OBJECT_ALLOCATOR
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Method Summary
 IRubyObject abort_on_exception_set(IRubyObject val)
           
static IRubyObject abort_on_exception_set(IRubyObject recv, IRubyObject value)
           
 RubyBoolean abort_on_exception()
           
static RubyBoolean abort_on_exception(IRubyObject recv)
          Returns the status of the global ``abort on exception'' condition.
static RubyThread adopt(IRubyObject recv, java.lang.Thread t)
           
 IRubyObject aref(IRubyObject key)
           
 IRubyObject aset(IRubyObject key, IRubyObject value)
           
 void cleanTerminate(IRubyObject result)
           
static RubyClass createThreadClass(Ruby runtime)
           
static IRubyObject critical_set(IRubyObject receiver, RubyBoolean value)
           
static IRubyObject critical(IRubyObject receiver)
           
static RubyThread current(IRubyObject recv)
           
 void exceptionRaised(RaiseException exception)
           
 IRubyObject exit()
           
 IRubyObject group()
           
 RubyBoolean has_key(IRubyObject key)
           
 IRubyObject initialize(IRubyObject[] args, Block block)
           
 IRubyObject inspect()
          rb_obj_inspect
 RubyBoolean is_alive()
           
 RubyBoolean isStopped()
           
 RubyThread join(IRubyObject[] args)
           
 RubyArray keys()
           
 IRubyObject kill()
           
static RubyArray list(IRubyObject recv)
           
static RubyThread main(IRubyObject recv)
           
static RubyThread mainThread(IRubyObject receiver)
           
static IRubyObject newInstance(IRubyObject recv, IRubyObject[] args, Block block)
          Thread.new
static IRubyObject pass(IRubyObject recv)
           
 void pollThreadEvents()
           
 IRubyObject priority_set(IRubyObject priority)
           
 RubyFixnum priority()
           
 IRubyObject raise(IRubyObject[] args, Block block)
           
 IRubyObject run()
           
static IRubyObject s_exit(IRubyObject receiver, Block block)
           
static IRubyObject s_kill(IRubyObject receiver, RubyThread rubyThread, Block block)
           
 void sleep(long millis)
           
static RubyThread start(IRubyObject recv, IRubyObject[] args, Block block)
          Basically the same as Thread.new .
 IRubyObject status()
           
static IRubyObject stop(IRubyObject receiver)
           
 IRubyObject value()
           
 RubyThread wakeup()
           
 
Methods inherited from class org.jruby.RubyObject
addFinalizer, anyToString, asString, asSymbol, attachToObjectSpace, callInit, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethodMissing, callMethodMissing, callSuper, checkArrayType, checkFrozen, checkStringType, compilerCallMethod, compilerCallMethodWithIndex, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToString, convertToType, convertToType, convertToType, convertToTypeWithCheck, createObjectClass, dataGetStruct, dataWrapStruct, display, doClone, dup, eql, eqlInternal, equal, equalInternal, equals, evalSimple, evalUnder, evalWithBinding, extend, freeze, frozen, getInstanceVariable, getInstanceVariables, getInstanceVariablesSnapshot, getJavaClass, getMetaClass, getNativeTypeIndex, getRuntime, getSingletonClass, getSingletonClassClone, getType, hash, hashCode, id_deprecated, id, infectBy, inherited, initCopy, initialize_copy, instance_eval, instance_exec, instance_of, instance_variable_get, instance_variable_set, instance_variables, instanceVariableNames, isFalse, isFrozen, isImmediate, isKindOf, isNil, isSingleton, isTaint, isTrue, kind_of, makeMetaClass, match, method, methods, nil_p, obj_equal, private_methods, protected_methods, public_methods, puts, rbClone, remove_instance_variable, removeFinalizers, removeInstanceVariable, respond_to, respondsTo, safeGetInstanceVariables, safeHasInstanceVariables, send, setFrozen, setInstanceVariable, setInstanceVariable, setInstanceVariables, setMetaClass, setTaint, singleton_methods, specificEval, taint, tainted, testFrozen, to_s, toString, trueFalseNil, trueFalseNil, type_deprecated, type, untaint
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

stopLock

public java.lang.Object stopLock

killLock

public java.lang.Object killLock

lock

public final ReentrantLock lock
Method Detail

createThreadClass

public static RubyClass createThreadClass(Ruby runtime)

newInstance

public static IRubyObject newInstance(IRubyObject recv,
                                      IRubyObject[] args,
                                      Block block)
Thread.new

Thread.new( [ arg ]* ) {| args | block } -> aThread

Creates a new thread to execute the instructions given in block, and begins running it. Any arguments passed to Thread.new are passed into the block.

 x = Thread.new { sleep .1; print "x"; print "y"; print "z" }
 a = Thread.new { print "a"; print "b"; sleep .2; print "c" }
 x.join # Let the threads finish before
 a.join # main thread exits...
 
produces: abxyzc


start

public static RubyThread start(IRubyObject recv,
                               IRubyObject[] args,
                               Block block)
Basically the same as Thread.new . However, if class Thread is subclassed, then calling start in that subclass will not invoke the subclass's initialize method.


adopt

public static RubyThread adopt(IRubyObject recv,
                               java.lang.Thread t)

initialize

public IRubyObject initialize(IRubyObject[] args,
                              Block block)
Overrides:
initialize in class RubyObject

cleanTerminate

public void cleanTerminate(IRubyObject result)

pollThreadEvents

public void pollThreadEvents()

abort_on_exception

public static RubyBoolean abort_on_exception(IRubyObject recv)
Returns the status of the global ``abort on exception'' condition. The default is false. When set to true, will cause all threads to abort (the process will exit(0)) if an exception is raised in any thread. See also Thread.abort_on_exception= .


abort_on_exception_set

public static IRubyObject abort_on_exception_set(IRubyObject recv,
                                                 IRubyObject value)

current

public static RubyThread current(IRubyObject recv)

main

public static RubyThread main(IRubyObject recv)

pass

public static IRubyObject pass(IRubyObject recv)

list

public static RubyArray list(IRubyObject recv)

aref

public IRubyObject aref(IRubyObject key)

aset

public IRubyObject aset(IRubyObject key,
                        IRubyObject value)

abort_on_exception

public RubyBoolean abort_on_exception()

abort_on_exception_set

public IRubyObject abort_on_exception_set(IRubyObject val)

is_alive

public RubyBoolean is_alive()

join

public RubyThread join(IRubyObject[] args)

value

public IRubyObject value()

group

public IRubyObject group()

inspect

public IRubyObject inspect()
Description copied from class: RubyObject
rb_obj_inspect

Specified by:
inspect in interface IRubyObject
Overrides:
inspect in class RubyObject
Returns:
String

has_key

public RubyBoolean has_key(IRubyObject key)

keys

public RubyArray keys()

critical_set

public static IRubyObject critical_set(IRubyObject receiver,
                                       RubyBoolean value)

critical

public static IRubyObject critical(IRubyObject receiver)

stop

public static IRubyObject stop(IRubyObject receiver)

s_kill

public static IRubyObject s_kill(IRubyObject receiver,
                                 RubyThread rubyThread,
                                 Block block)

s_exit

public static IRubyObject s_exit(IRubyObject receiver,
                                 Block block)

isStopped

public RubyBoolean isStopped()

wakeup

public RubyThread wakeup()

priority

public RubyFixnum priority()

priority_set

public IRubyObject priority_set(IRubyObject priority)

raise

public IRubyObject raise(IRubyObject[] args,
                         Block block)

run

public IRubyObject run()

sleep

public void sleep(long millis)
           throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

status

public IRubyObject status()

kill

public IRubyObject kill()

exit

public IRubyObject exit()

exceptionRaised

public void exceptionRaised(RaiseException exception)

mainThread

public static RubyThread mainThread(IRubyObject receiver)


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