public class RubyThread extends RubyObject implements ExecutionContext
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.
Modifier and Type | Class and Description |
---|---|
static interface |
RubyThread.BlockingTask |
static class |
RubyThread.Location |
static class |
RubyThread.SleepTask |
static class |
RubyThread.Status
Thread statuses
|
RubyObject.Data
RubyBasicObject.Finalizer
FIELD_ALLOCATED_CLASSES, FIELD_ALLOCATORS, IVAR_INSPECTING_OBJECT_ALLOCATOR, OBJECT_ALLOCATOR, OBJECT_VAR0_ALLOCATOR, OBJECT_VAR1_ALLOCATOR, OBJECT_VAR2_ALLOCATOR, OBJECT_VAR3_ALLOCATOR, OBJECT_VAR4_ALLOCATOR, OBJECT_VAR5_ALLOCATOR, OBJECT_VAR6_ALLOCATOR, OBJECT_VAR7_ALLOCATOR, OBJECT_VAR8_ALLOCATOR, OBJECT_VAR9_ALLOCATOR, REIFYING_OBJECT_ALLOCATOR
ALL_F, BASICOBJECT_ALLOCATOR, COMPARE_BY_IDENTITY_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, metaClass, NEVER, NIL_F, STAMP_OFFSET, TAINTED_F, UNDEF, UNTRUSTED_F, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, USER8_F, VAR_TABLE_OFFSET, varTable, varTableStamp
NULL_ARRAY
Modifier | Constructor and Description |
---|---|
protected |
RubyThread(Ruby runtime,
RubyClass type) |
|
RubyThread(Ruby runtime,
RubyClass klass,
ThreadedRunnable runnable) |
Modifier and Type | Method and Description |
---|---|
static IRubyObject |
abort_on_exception_set_x(IRubyObject recv,
IRubyObject value) |
IRubyObject |
abort_on_exception_set(IRubyObject val) |
static RubyBoolean |
abort_on_exception_x(IRubyObject recv)
Returns the status of the global ``abort on exception'' condition.
|
RubyBoolean |
abort_on_exception() |
static RubyThread |
adopt(IRubyObject recv,
Thread t) |
void |
afterBlockingCall() |
RubyBoolean |
alive_p() |
IRubyObject |
backtrace_locations(ThreadContext context,
IRubyObject[] args) |
IRubyObject |
backtrace(ThreadContext context) |
IRubyObject |
backtrace20(ThreadContext context,
IRubyObject[] args) |
void |
beDead() |
void |
beforeBlockingCall() |
void |
beforeStart()
Perform pre-execution tasks once the native thread is running, but we
have not yet called the Ruby code for the thread.
|
void |
checkMail(ThreadContext context) |
void |
cleanTerminate(IRubyObject result) |
static RubyClass |
createThreadClass(Ruby runtime) |
static IRubyObject |
critical_set(IRubyObject receiver,
IRubyObject value) |
static IRubyObject |
critical(IRubyObject receiver) |
static RubyThread |
current(IRubyObject recv) |
void |
dieFromFinalizer()
Used for finalizers that need to kill a Ruby thread.
|
void |
dispose()
Dispose of the current thread by tidying up connections to other stuff
|
void |
enterSleep() |
boolean |
equals(Object obj)
This method is just a wrapper around the Ruby "==" method,
provided so that RubyObjects can be used as keys in the Java
HashMap object underlying RubyHash.
|
void |
exceptionRaised(RaiseException exception) |
void |
exceptionRaised(Throwable exception)
For handling all non-Ruby exceptions bubbling out of threads
|
void |
executeBlockingTask(RubyThread.BlockingTask task) |
static IRubyObject |
exit(IRubyObject receiver,
Block block) |
void |
exitSleep() |
ThreadContext |
getContext() |
Map<Object,IRubyObject> |
getContextVariables() |
IRubyObject |
getErrorInfo() |
Thread |
getNativeThread() |
RubyThreadGroup |
getThreadGroup() |
IRubyObject |
group() |
int |
hashCode()
Override the Object#hashCode method to make sure that the Ruby
hash is actually used as the hashcode for Ruby objects.
|
IRubyObject |
initialize(ThreadContext context,
IRubyObject[] args,
Block block) |
IRubyObject |
inspect()
rb_obj_inspect
call-seq:
obj.inspect => string
Returns a string containing a human-readable representation of
obj.
|
void |
internalRaise(IRubyObject[] args)
This is intended to be used to raise exceptions in Ruby threads from non-
Ruby threads like Timeout's thread.
|
void |
interrupt() |
boolean |
isAlive() |
StackTraceElement[] |
javaBacktrace() |
IRubyObject |
join(IRubyObject[] args) |
RubyBoolean |
key_p(IRubyObject key) |
RubyArray |
keys() |
IRubyObject |
kill_bang() |
IRubyObject |
kill() |
static IRubyObject |
kill(IRubyObject receiver,
IRubyObject rubyThread,
Block block) |
static RubyArray |
list(IRubyObject recv) |
void |
lock(Lock lock)
Acquire the given lock, holding a reference to it for cleanup on thread
termination.
|
void |
lockInterruptibly(Lock lock)
Acquire the given lock interruptibly, holding a reference to it for cleanup
on thread termination.
|
static RubyThread |
main(IRubyObject recv) |
static RubyThread |
mainThread(IRubyObject receiver) |
static IRubyObject |
newInstance(IRubyObject recv,
IRubyObject[] args,
Block block)
Thread.new |
IRubyObject |
op_aref(IRubyObject key) |
IRubyObject |
op_aset(IRubyObject key,
IRubyObject value) |
static IRubyObject |
pass(IRubyObject recv) |
void |
pollThreadEvents() |
void |
pollThreadEvents(ThreadContext context) |
IRubyObject |
priority_set(IRubyObject priority) |
RubyFixnum |
priority() |
IRubyObject |
raise(IRubyObject exception)
Simplified utility method for just raising an existing exception in this
thread.
|
IRubyObject |
raise(IRubyObject[] args,
Block block) |
void |
receiveMail(ThreadService.Event event) |
IRubyObject |
run() |
IRubyObject |
safe_level() |
boolean |
select(Channel channel,
RubyIO io,
int ops) |
boolean |
select(Channel channel,
RubyIO io,
int ops,
long timeout) |
boolean |
select(RubyIO io,
int ops) |
boolean |
select(RubyIO io,
int ops,
long timeout) |
boolean |
selectForAccept(RubyIO io)
Deprecated.
|
void |
setContext(ThreadContext context) |
IRubyObject |
setErrorInfo(IRubyObject errorInfo) |
boolean |
sleep(long millis)
We can never be sure if a wait will finish because of a Java "spurious wakeup".
|
static RubyThread |
start(IRubyObject recv,
IRubyObject[] args,
Block block)
Basically the same as Thread.new .
|
static RubyThread |
start19(IRubyObject recv,
IRubyObject[] args,
Block block) |
IRubyObject |
status() |
IRubyObject |
status(ThreadContext context) |
RubyBoolean |
stop_p() |
static IRubyObject |
stop(ThreadContext context,
IRubyObject receiver) |
String |
toString()
The default toString method is just a wrapper that calls the
Ruby "to_s" method.
|
boolean |
tryLock(Lock lock)
Try to acquire the given lock, adding it to a list of held locks for cleanup
on thread termination if it is acquired.
|
void |
unlock(Lock lock)
Release the given lock and remove it from the list of locks to be released
on thread termination.
|
void |
unlockAll()
Release all locks held.
|
IRubyObject |
value() |
boolean |
wait_timeout(IRubyObject o,
Double timeout) |
boolean |
waitForIO(ThreadContext context,
RubyIO io,
int ops) |
RubyThread |
wakeup() |
attachToObjectSpace, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, convertToType, createObjectClass, eqlInternal, equalInternal, getNativeTypeIndex, initialize, initialize, inspect, op_eqq, puts, specificEval
addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkFrozen, checkStringType, checkStringType19, compareTo, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, createBasicObjectClass, dataGetStruct, dataGetStructChecked, dataWrapStruct, display, dup, ensureInstanceVariablesSettable, eql_p, eql, equal_p, equal_p19, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, freeze, frozen_p, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMetaClass, getNativeHandle, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hash, hashyInspect, hasInstanceVariable, hasInternalVariable, hasVariables, id_deprecated, id, infectBy, initialize_copy, initialize19, inspectHashCode, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval19, instance_eval19, instance_eval19, instance_eval19, instance_exec, instance_exec19, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, instance_variables19, isBuiltin, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, method_missing19, method, method19, methods, methods, methods19, nil_p, op_cmp, op_equal_19, op_equal, op_match, op_match19, op_not_equal, op_not_match, op_not, private_methods, private_methods19, protected_methods, protected_methods19, public_methods, public_methods19, rbClone, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respond_to_p19, respond_to_p19, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, send19, send19, send19, send19, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setNativeHandle, setTaint, setUntrusted, setVariable, singleton_method_added19, singleton_method_removed19, singleton_method_undefined19, singleton_methods, singleton_methods19, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, taint, tainted_p, testFrozen, testFrozen, to_a, to_s, toJava, trust, type_deprecated, type, untaint, untrust, untrusted_p, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnder
public RubyThread(Ruby runtime, RubyClass klass, ThreadedRunnable runnable)
public void receiveMail(ThreadService.Event event)
public void checkMail(ThreadContext context)
public IRubyObject getErrorInfo()
public IRubyObject setErrorInfo(IRubyObject errorInfo)
public void setContext(ThreadContext context)
public ThreadContext getContext()
public Thread getNativeThread()
public void beforeStart()
public void dispose()
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
public static RubyThread start(IRubyObject recv, IRubyObject[] args, Block block)
public static RubyThread start19(IRubyObject recv, IRubyObject[] args, Block block)
public static RubyThread adopt(IRubyObject recv, Thread t)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block)
public void cleanTerminate(IRubyObject result)
public void beDead()
public void pollThreadEvents()
public void pollThreadEvents(ThreadContext context)
public static RubyBoolean abort_on_exception_x(IRubyObject recv)
public static IRubyObject abort_on_exception_set_x(IRubyObject recv, IRubyObject value)
public static RubyThread current(IRubyObject recv)
public static RubyThread main(IRubyObject recv)
public static IRubyObject pass(IRubyObject recv)
public static RubyArray list(IRubyObject recv)
public final Map<Object,IRubyObject> getContextVariables()
getContextVariables
in interface ExecutionContext
public boolean isAlive()
public IRubyObject op_aref(IRubyObject key)
public IRubyObject op_aset(IRubyObject key, IRubyObject value)
public RubyBoolean abort_on_exception()
public IRubyObject abort_on_exception_set(IRubyObject val)
public RubyBoolean alive_p()
public IRubyObject join(IRubyObject[] args)
public IRubyObject value()
public IRubyObject group()
public IRubyObject inspect()
RubyBasicObject
to_s
method to
generate the string.
[ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]"
Time.new.inspect #=> "Wed Apr 09 08:54:39 CDT 2003"inspect
in interface IRubyObject
inspect
in class RubyBasicObject
public RubyBoolean key_p(IRubyObject key)
public RubyArray keys()
public static IRubyObject critical_set(IRubyObject receiver, IRubyObject value)
public static IRubyObject critical(IRubyObject receiver)
public static IRubyObject stop(ThreadContext context, IRubyObject receiver)
public static IRubyObject kill(IRubyObject receiver, IRubyObject rubyThread, Block block)
public static IRubyObject exit(IRubyObject receiver, Block block)
public RubyBoolean stop_p()
public RubyThread wakeup()
public RubyFixnum priority()
public IRubyObject priority_set(IRubyObject priority)
public IRubyObject raise(IRubyObject exception)
exception
- the exception to raisepublic IRubyObject raise(IRubyObject[] args, Block block)
public void internalRaise(IRubyObject[] args)
args
- Same args as for Thread#raiseblock
- Same as for Thread#raisepublic IRubyObject run()
public boolean sleep(long millis) throws InterruptedException
InterruptedException
public IRubyObject status()
public IRubyObject status(ThreadContext context)
public void executeBlockingTask(RubyThread.BlockingTask task) throws InterruptedException
InterruptedException
public void enterSleep()
public void exitSleep()
public IRubyObject kill()
public void dieFromFinalizer()
public IRubyObject kill_bang()
public IRubyObject safe_level()
public IRubyObject backtrace(ThreadContext context)
public IRubyObject backtrace20(ThreadContext context, IRubyObject[] args)
public IRubyObject backtrace_locations(ThreadContext context, IRubyObject[] args)
public StackTraceElement[] javaBacktrace()
public void exceptionRaised(RaiseException exception)
public void exceptionRaised(Throwable exception)
exception
- public static RubyThread mainThread(IRubyObject receiver)
@Deprecated public boolean selectForAccept(RubyIO io)
public boolean select(RubyIO io, int ops)
public boolean select(RubyIO io, int ops, long timeout)
public void interrupt()
public boolean waitForIO(ThreadContext context, RubyIO io, int ops)
public void beforeBlockingCall()
public void afterBlockingCall()
public boolean wait_timeout(IRubyObject o, Double timeout) throws InterruptedException
InterruptedException
public RubyThreadGroup getThreadGroup()
public boolean equals(Object obj)
RubyObject
equals
in class RubyObject
public int hashCode()
RubyObject
hashCode
in class RubyObject
public String toString()
RubyObject
toString
in class RubyObject
public void lock(Lock lock)
lock
- the lock to acquire, released on thread terminationpublic void lockInterruptibly(Lock lock) throws InterruptedException
lock
- the lock to acquire, released on thread terminationInterruptedException
- if the lock acquisition is interruptedpublic boolean tryLock(Lock lock)
lock
- the lock to acquire, released on thread terminationpublic void unlock(Lock lock)
lock
- the lock to release and dereferencespublic void unlockAll()
Copyright © 2001-2016 JRuby. All Rights Reserved.