Package org.jruby
Class RubyThread
java.lang.Object
org.jruby.RubyBasicObject
org.jruby.RubyObject
org.jruby.RubyThread
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<IRubyObject>,InstanceVariables,InternalVariables,IRubyObject,ExecutionContext,CoreObjectType
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.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interfaceDeprecated.static classstatic interfacestatic interfacestatic final classstatic enumThread statusesstatic interfacestatic interfaceNested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.DataNested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.Finalizer -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intFields inherited from class org.jruby.RubyObject
IVAR_INSPECTING_OBJECT_ALLOCATOR, OBJECT_ALLOCATOR, REIFYING_OBJECT_ALLOCATORFields inherited from class org.jruby.RubyBasicObject
ALL_F, BASICOBJECT_ALLOCATOR, COMPARE_BY_IDENTITY_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, IS_OVERLAID_F, metaClass, NEVER, NIL_F, REFINED_MODULE_F, STAMP_OFFSET, TAINTED_F, UNDEF, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, USER8_F, USER9_F, USERA_F, VAR_TABLE_OFFSET, varTable, varTableStamp -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRubyThread(Ruby runtime, RubyClass type, boolean adopted) RubyThread(Ruby runtime, RubyClass klass, Runnable runnable) -
Method Summary
Modifier and TypeMethodDescriptionabort_on_exception(ThreadContext context) static RubyBooleanabort_on_exception(ThreadContext context, IRubyObject recv) Returns the status of the global ``abort on exception'' condition.static IRubyObjectabort_on_exception_set(ThreadContext context, IRubyObject recv, IRubyObject value) add_trace_func(ThreadContext context, IRubyObject trace_func, Block block) static IRubyObjectadd_trace_func(ThreadContext context, IRubyObject recv, IRubyObject trace_func, Block block) static RubyThreadadopt(Ruby runtime, ThreadService service, Thread thread) static RubyThreadadopt(IRubyObject recv, Thread t) voidalive_p()Deprecated.alive_p(ThreadContext context) backtrace(ThreadContext context) backtrace(ThreadContext context, IRubyObject level) backtrace(ThreadContext context, IRubyObject level, IRubyObject length) backtrace_locations(ThreadContext context) backtrace_locations(ThreadContext context, IRubyObject level) backtrace_locations(ThreadContext context, IRubyObject level, IRubyObject length) voidbeDead()voidDeprecated.voidbeforeBlockingCall(ThreadContext context) voidPerform pre-execution tasks once the native thread is running, but we have not yet called the Ruby code for the thread.voidblockingThreadPoll(ThreadContext context) voidcleanTerminate(IRubyObject result) voidvoidClear the fiber local variable storage for this thread.voidClear the thread local variable storage for this thread.static RubyClasscreateThreadClass(ThreadContext context, RubyClass Object) static RubyThreadcurrent(IRubyObject recv) voidvoidUsed for finalizers that need to kill a Ruby thread.voiddispose()Dispose of the current thread by tidying up connections to other stuffstatic IRubyObjecteach_caller_location(ThreadContext context, IRubyObject recv, Block block) voidbooleanThis override does not do a "checked" dispatch.voidexceptionRaised(Throwable throwable) For handling all exceptions bubbling out of threadsvoidexceptionRaised(RaiseException exception) voidDeprecated.<Data> intexecuteReadWrite(ThreadContext context, Data data, byte[] bytes, int start, int length, RubyThread.ReadWrite<Data> task) Execute an interruptible read or write operation with the given byte range and data object.<Data> intexecuteReadWrite(ThreadContext context, Data data, ByteBuffer bytes, int start, int length, RubyThread.ReadWrite<Data> task) <Data> intexecuteRegexp(ThreadContext context, org.joni.Matcher matcher, int start, int range, int option, RubyThread.RegexMatch task) Execute an interruptible regexp operation with the given function and bytess.<Data,Return>
ReturnexecuteTask(ThreadContext context, Data data, RubyThread.Status status, RubyThread.Task<Data, Return> task) <Data,Return>
ReturnexecuteTask(ThreadContext context, Data data, RubyThread.Task<Data, Return> task) <Data,Return>
ReturnexecuteTaskBlocking(ThreadContext context, Data data, RubyThread.Status status, RubyThread.Task<Data, Return> task) <Data,Return>
ReturnexecuteTaskBlocking(ThreadContext context, Data data, RubyThread.Task<Data, Return> task) static IRubyObjectexit(IRubyObject receiver, Block block) voidfetch(ThreadContext context, IRubyObject key, Block block) fetch(ThreadContext context, IRubyObject key, IRubyObject _default, Block block) final Map<Object, IRubyObject> getName()Deprecated.getName(ThreadContext context) group()static IRubyObjecthandle_interrupt(ThreadContext context, IRubyObject self, IRubyObject _mask, Block block) inthashCode()This override does not do "checked" dispatch since Object usually has #hash defined.voidinitialize(ThreadContext context, IRubyObject[] args, Block block) inspect(ThreadContext context) Returns a string containing a human-readable representation of obj.voidbooleanbooleanbooleanisAlive()booleanbooleanstatic intjavaPriorityToRubyPriority(int javaPriority) join(ThreadContext context) join(ThreadContext context, IRubyObject timeout) join(ThreadContext context, IRubyObject[] args) Deprecated.key_p(ThreadContext context, IRubyObject key) keys()kill()static IRubyObjectkill(IRubyObject recv, IRubyObject rubyThread, Block block) static RubyArraylist(IRubyObject recv) voidAcquire the given lock, holding a reference to it for cleanup on thread termination.voidlockInterruptibly(Lock lock) Acquire the given lock interruptibly, holding a reference to it for cleanup on thread termination.static RubyThreadmain(IRubyObject recv) static RubyThreadmainThread(IRubyObject receiver) native_thread_id(ThreadContext context) static IRubyObjectnewInstance(IRubyObject recv, IRubyObject[] args, Block block) Thread.newop_aref(ThreadContext context, IRubyObject key) op_aset(IRubyObject key, IRubyObject value) Deprecated.op_aset(ThreadContext context, IRubyObject key, IRubyObject value) static IRubyObjectpass(ThreadContext context, IRubyObject recv) pending_interrupt_p(ThreadContext context) pending_interrupt_p(ThreadContext context, IRubyObject err) pending_interrupt_p(ThreadContext context, IRubyObject[] args) Deprecated.static IRubyObjectpending_interrupt_p(ThreadContext context, IRubyObject self, IRubyObject[] args) Deprecated.static IRubyObjectpending_interrupt_p_s(ThreadContext context, IRubyObject self) static IRubyObjectpending_interrupt_p_s(ThreadContext context, IRubyObject self, IRubyObject err) voidvoidpollThreadEvents(ThreadContext context) voidpollThreadEvents(ThreadContext context, boolean blocking) Poll for thread events (raise, kill), propagating only events that are unmasked (seehandle_interrupt(ThreadContext, IRubyObject, IRubyObject, Block)or intended to fire before blocking operations if blocking = true.static IRubyObjectprepareRaiseException(ThreadContext context, IRubyObject[] args) protected voidpriority()Deprecated.priority(ThreadContext context) priority_set(IRubyObject priority) Deprecated.priority_set(ThreadContext context, IRubyObject priority) final IRubyObjectraise(IRubyObject exception) Simplified utility method for just raising an existing exception in this thread.final IRubyObjectraise(IRubyObject exception, RubyString message) Simplified utility method for just raising an existing exception in this thread.raise(ThreadContext context, IRubyObject[] args, Block block) report_on_exception(ThreadContext context) static IRubyObjectreport_on_exception(ThreadContext context, IRubyObject self) report_on_exception_set(ThreadContext context, IRubyObject state) static IRubyObjectreport_on_exception_set(ThreadContext context, IRubyObject self, IRubyObject state) static intrubyPriorityToJavaPriority(int rubyPriority) run()booleanPerform an interruptible select operation on the given channel and fptr, waiting for the requested operations.booleanPerform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.booleanPerform an interruptible select operation on the given channel and fptr, waiting for the requested operations.booleanPerform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.booleanPerform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.booleanPerform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.set_trace_func(ThreadContext context, IRubyObject trace_func, Block block) voidsetAbortOnException(boolean abortOnException) voidsetContext(ThreadContext context) setErrorInfo(IRubyObject errorInfo) voidsetFiberCurrentThread(RubyThread fiberCurrentThread) setFiberScheduler(IRubyObject scheduler) Deprecated.setFiberScheduler(ThreadContext context, IRubyObject scheduler) Set the scheduler for the current thread.voidSet the pending interrupt flag.setName(IRubyObject name) Deprecated.setName(ThreadContext context, IRubyObject name) voidsetReportOnException(boolean reportOnException) booleansleep(long milliseconds) Sleep the current thread for milliseconds, waking up on any thread interrupts.booleansleep(long milliseconds, long nanoseconds) Sleep the current thread for milliseconds + nanoseconds, waking up on any thread interrupts.voidRelease lock and sleep.voidRelease lock and sleep for the specified number of milliseconds.static RubyThreadstart(IRubyObject recv, IRubyObject[] args, Block block) Deprecated.static RubyThreadstart(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) Basically the same as Thread.new .protected static RubyThreadstartWaiterThread(Ruby runtime, long pid, Block block) status()status(ThreadContext context) static IRubyObjectstop(ThreadContext context, IRubyObject receiver) stop_p()Deprecated.stop_p(ThreadContext context) thread_variable_get(ThreadContext context, IRubyObject key) thread_variable_p(ThreadContext context, IRubyObject key) thread_variable_set(ThreadContext context, IRubyObject key, IRubyObject value) thread_variables(ThreadContext context) <T> TCustomized for retrieving a Java thread from a Ruby one.toString()The default toString method is just a wrapper that calls the Ruby "to_s" method.booleanTry to acquire the given lock, adding it to a list of held locks for cleanup on thread termination if it is acquired.static <StateType>
IRubyObjectuninterruptible(ThreadContext context, StateType state, BiFunction<ThreadContext, StateType, IRubyObject> f) Run the providedBiFunctionwithout allowing for any cross-thread interrupts (equivalent to callinghandle_interrupt(ThreadContext, IRubyObject, IRubyObject, Block)with Object => :never.voidRelease the given lock and remove it from the list of locks to be released on thread termination.voidRelease all locks held.value()Deprecated.value(ThreadContext context) booleanwait_timeout(IRubyObject o, Double timeout) booleanwaitForIO(ThreadContext context, RubyIO io, int ops) wakeup()Methods inherited from class org.jruby.RubyObject
attachToObjectSpace, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, convertToType, dig, dig1, dig2, eqlInternal, equalInternal, finishObjectClass, getNativeClassIndex, inspect, op_eqq, puts, specificEval, toRubyStringMethods inherited from class org.jruby.RubyBasicObject
addFinalizer, addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, cloneSetup, compareTo, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, dataGetStruct, dataGetStructChecked, dataWrapStruct, decode, display, dup, dupFinalizer, dupSetup, ensureInstanceVariablesSettable, eql, eql_p, eql_p, equal_p, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, finishBasicObjectClass, forEachInstanceVariable, forEachInstanceVariableName, freeze, frozen_p, getCurrentContext, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMarshalVariableList, getMetaClass, getMetaClass, getNativeHandle, getNativeTypeIndex, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getSingletonClassCloneAndAttach, getSingletonClassCloneAndAttach, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hash, hash, hashyInspect, hasInstanceVariable, hasInstanceVariables, hasInternalVariable, hasVariables, id, infectBy, initialize, initialize_copy, initialize_copy, inspect, inspectHashCode, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval, instance_exec, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, isBuiltin, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isSpecialConst, isSpecialObject, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, makeMetaClass, makeMetaClassBootstrap, method, method, method, method_missing, methods, methods, nil_p, nonFixnumHashCode, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_cmp, op_equal, op_match, op_not, op_not_equal, op_not_match, private_methods, protected_methods, public_methods, rbClone, rbClone, rbInspect, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setNativeHandle, setTaint, setUntrusted, setVariable, singleton_method, singleton_method, singleton_method_added, singleton_method_removed, singleton_method_undefined, singleton_methods, singletonClass, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, taint, tainted_p, testFrozen, testFrozen, to_a, to_a, to_s, to_s, trust, type, untaint, untrust, untrusted_p, validateInstanceVariable, validateInstanceVariable, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnderMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jruby.runtime.builtin.IRubyObject
checkStringType19, dup, marshalLiveVariables
-
Field Details
-
RUBY_MIN_THREAD_PRIORITY
public static final int RUBY_MIN_THREAD_PRIORITY- See Also:
-
RUBY_MAX_THREAD_PRIORITY
public static final int RUBY_MAX_THREAD_PRIORITY- See Also:
-
-
Constructor Details
-
RubyThread
-
RubyThread
-
-
Method Details
-
getErrorInfo
-
setErrorInfo
-
setContext
-
clearContext
public void clearContext() -
getContext
-
getNativeThread
-
setFiberCurrentThread
-
getFiberCurrentThread
-
beforeStart
public void beforeStart()Perform pre-execution tasks once the native thread is running, but we have not yet called the Ruby code for the thread. -
dispose
public void dispose()Dispose of the current thread by tidying up connections to other stuff -
createThreadClass
-
newInstance
Thread.newThread.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
@Deprecated(since="10.0") public static RubyThread start(IRubyObject recv, IRubyObject[] args, Block block) Deprecated. -
start
public static RubyThread start(ThreadContext context, 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
-
adopt
-
initialize
-
startWaiterThread
-
cleanTerminate
-
beDead
public void beDead() -
pollThreadEvents
public void pollThreadEvents() -
pollThreadEvents
Poll for thread events (raise, kill), propagating only events that are unmasked (seehandle_interrupt(ThreadContext, IRubyObject, IRubyObject, Block)or intended to fire before blocking operations if blocking = true.- Parameters:
context- the contextblocking- whether to trigger blocking operation interrupts
-
pollThreadEvents
-
blockingThreadPoll
-
handle_interrupt
public static IRubyObject handle_interrupt(ThreadContext context, IRubyObject self, IRubyObject _mask, Block block) -
pending_interrupt_p_s
-
pending_interrupt_p_s
public static IRubyObject pending_interrupt_p_s(ThreadContext context, IRubyObject self, IRubyObject err) -
pending_interrupt_p
-
pending_interrupt_p
-
setName
Deprecated. -
setName
-
getName
Deprecated. -
getName
-
current
-
main
-
pass
-
list
-
add_trace_func
-
add_trace_func
public static IRubyObject add_trace_func(ThreadContext context, IRubyObject recv, IRubyObject trace_func, Block block) -
set_trace_func
-
clearFiberLocals
public void clearFiberLocals()Clear the fiber local variable storage for this thread. Meant for Java consumers when reusing threads (e.g. during thread pooling).- See Also:
-
clearThreadLocals
public void clearThreadLocals()Clear the thread local variable storage for this thread. Meant for Java consumers when reusing threads (e.g. during thread pooling).- See Also:
-
getContextVariables
- Specified by:
getContextVariablesin interfaceExecutionContext
-
isAlive
public boolean isAlive() -
isAdopted
public boolean isAdopted() -
fetch
-
fetch
-
op_aref
-
op_aset
-
key_p
-
keys
-
thread_variable_p
-
thread_variable_get
-
thread_variable_set
-
thread_variables
-
isAbortOnException
public boolean isAbortOnException() -
setAbortOnException
public void setAbortOnException(boolean abortOnException) -
abort_on_exception
-
abort_on_exception_set
-
abort_on_exception
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(ThreadContext context, IRubyObject recv, IRubyObject value) -
alive_p
-
join
-
join
-
value
-
group
-
inspect
Description copied from class:RubyBasicObjectReturns a string containing a human-readable representation of obj. If not overridden, uses theto_smethod 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"- Specified by:
inspectin interfaceIRubyObject- Overrides:
inspectin classRubyBasicObject
-
stop
-
kill
-
exit
-
stop_p
-
stop_p
Deprecated. -
wakeup
-
priority
Deprecated. -
priority
-
priority_set
Deprecated. -
priority_set
-
javaPriorityToRubyPriority
public static int javaPriorityToRubyPriority(int javaPriority) -
rubyPriorityToJavaPriority
public static int rubyPriorityToJavaPriority(int rubyPriority) -
raise
Simplified utility method for just raising an existing exception in this thread.- Parameters:
exception- the exception to raise- Returns:
- this thread
-
raise
Simplified utility method for just raising an existing exception in this thread.- Parameters:
exception- the exception to raisemessage- the message to use- Returns:
- this thread
-
raise
-
native_thread_id
-
prepareRaiseException
-
run
-
sleep
Sleep the current thread for milliseconds, waking up on any thread interrupts.- Parameters:
milliseconds- Number of milliseconds to sleep. Zero sleeps forever.- Throws:
InterruptedException
-
sleep
Sleep the current thread for milliseconds + nanoseconds, waking up on any thread interrupts. We can never be sure if a wait will finish because of a Java "spurious wakeup". So if we explicitly wakeup and we wait less than requested amount we will return false. We will return true if we sleep right amount or less than right amount via spurious wakeup.- Parameters:
milliseconds- Number of milliseconds to sleep. Combined with nanoseconds, zero sleeps forever.nanoseconds- Number of nanoseconds to sleep. Combined with milliseconds, zero sleeps forever.- Throws:
InterruptedException
-
status
-
status
-
each_caller_location
public static IRubyObject each_caller_location(ThreadContext context, IRubyObject recv, Block block) -
getExitingException
- Returns:
- existing exception or null if terminated normally
-
executeBlockingTask
@Deprecated public void executeBlockingTask(RubyThread.BlockingTask task) throws InterruptedException Deprecated.- Throws:
InterruptedException
-
executeTaskBlocking
public <Data,Return> Return executeTaskBlocking(ThreadContext context, Data data, RubyThread.Task<Data, Return> task) throws InterruptedException- Throws:
InterruptedException
-
executeTask
public <Data,Return> Return executeTask(ThreadContext context, Data data, RubyThread.Task<Data, Return> task) throws InterruptedException- Throws:
InterruptedException
-
executeTaskBlocking
public <Data,Return> Return executeTaskBlocking(ThreadContext context, Data data, RubyThread.Status status, RubyThread.Task<Data, Return> task) throws InterruptedException- Throws:
InterruptedException
-
executeTask
public <Data,Return> Return executeTask(ThreadContext context, Data data, RubyThread.Status status, RubyThread.Task<Data, Return> task) throws InterruptedException- Throws:
InterruptedException
-
executeReadWrite
public <Data> int executeReadWrite(ThreadContext context, Data data, byte[] bytes, int start, int length, RubyThread.ReadWrite<Data> task) throws InterruptedException Execute an interruptible read or write operation with the given byte range and data object.- Type Parameters:
Data- the type of the data object- Parameters:
context- the current contextdata- a data objectbytes- the bytes to writestart- start range of bytes to writelength- length of bytes to writetask- the write task- Returns:
- the number of bytes written
- Throws:
InterruptedException
-
executeReadWrite
public <Data> int executeReadWrite(ThreadContext context, Data data, ByteBuffer bytes, int start, int length, RubyThread.ReadWrite<Data> task) throws InterruptedException - Throws:
InterruptedException
-
executeRegexp
public <Data> int executeRegexp(ThreadContext context, org.joni.Matcher matcher, int start, int range, int option, RubyThread.RegexMatch task) throws InterruptedException Execute an interruptible regexp operation with the given function and bytess.- Type Parameters:
Data-- Parameters:
context-matcher-start-range-option-task-- Returns:
- ""
- Throws:
InterruptedException- when interrupted
-
enterSleep
public void enterSleep() -
exitSleep
public void exitSleep() -
kill
-
dieFromFinalizer
public void dieFromFinalizer()Used for finalizers that need to kill a Ruby thread. Finalizers run in a VM thread to which we do not want to attach a ThreadContext and within which we do not want to check for Ruby thread events. This mechanism goes directly to mail delivery, bypassing all Ruby Thread-related steps. -
backtrace
-
backtrace
-
backtrace
-
backtrace_locations
-
backtrace_locations
-
backtrace_locations
public IRubyObject backtrace_locations(ThreadContext context, IRubyObject level, IRubyObject length) -
isReportOnException
public boolean isReportOnException() -
setReportOnException
public void setReportOnException(boolean reportOnException) -
report_on_exception_set
-
report_on_exception
-
report_on_exception_set
public static IRubyObject report_on_exception_set(ThreadContext context, IRubyObject self, IRubyObject state) -
report_on_exception
-
javaBacktrace
-
exceptionRaised
-
printReportExceptionWarning
protected void printReportExceptionWarning() -
exceptionRaised
For handling all exceptions bubbling out of threads- Parameters:
throwable-
-
mainThread
-
select
Perform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.- Parameters:
io- the RubyIO that contains the channel, for managing blocked threads list.ops- the operations to wait for, fromSelectionKey.- Returns:
- true if the IO's channel became ready for the requested operations, false if it was not selectable.
-
select
Perform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.- Parameters:
io- the RubyIO that contains the channel, for managing blocked threads list.ops- the operations to wait for, fromSelectionKey.timeout- a timeout in ms to limit the select. Less than zero selects forever, zero selects and returns ready channels or nothing immediately, and greater than zero selects for at most that many ms.- Returns:
- true if the IO's channel became ready for the requested operations, false if it timed out or was not selectable.
-
select
Perform an interruptible select operation on the given channel and fptr, waiting for the requested operations.- Parameters:
channel- the channel to perform a select against. If this is not a selectable channel, then this method will just return true.fptr- the fptr that contains the channel, for managing blocked threads list.ops- the operations to wait for, fromSelectionKey.- Returns:
- true if the channel became ready for the requested operations, false if it was not selectable.
-
select
Perform an interruptible select operation on the given channel and fptr, waiting for the requested operations.- Parameters:
channel- the channel to perform a select against. If this is not a selectable channel, then this method will just return true.io- the RubyIO that contains the channel, for managing blocked threads list.ops- the operations to wait for, fromSelectionKey.- Returns:
- true if the channel became ready for the requested operations, false if it was not selectable.
-
select
Perform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.- Parameters:
channel- the channel to perform a select against. If this is not a selectable channel, then this method will just return true.io- the RubyIO that contains the channel, for managing blocked threads list.ops- the operations to wait for, fromSelectionKey.timeout- a timeout in ms to limit the select. Less than zero selects forever, zero selects and returns ready channels or nothing immediately, and greater than zero selects for at most that many ms.- Returns:
- true if the channel became ready for the requested operations, false if it timed out or was not selectable.
-
select
Perform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.- Parameters:
channel- the channel to perform a select against. If this is not a selectable channel, then this method will just return true.fptr- the fptr that contains the channel, for managing blocked threads list.ops- the operations to wait for, fromSelectionKey.timeout- a timeout in ms to limit the select. Less than zero selects forever, zero selects and returns ready channels or nothing immediately, and greater than zero selects for at most that many ms.- Returns:
- true if the channel became ready for the requested operations, false if it timed out or was not selectable.
-
interrupt
public void interrupt() -
setInterrupt
public void setInterrupt()Set the pending interrupt flag. CRuby: RB_VM_SET_INTERRUPT/ -
waitForIO
-
beforeBlockingCall
-
beforeBlockingCall
Deprecated. -
afterBlockingCall
public void afterBlockingCall() -
wait_timeout
- Throws:
InterruptedException
-
getThreadGroup
-
equals
Description copied from class:RubyObjectThis override does not do a "checked" dispatch.- Overrides:
equalsin classRubyObject- Parameters:
obj- object to compare- Returns:
- true if equals
- See Also:
-
hashCode
public int hashCode()Description copied from class:RubyObjectThis override does not do "checked" dispatch since Object usually has #hash defined.- Overrides:
hashCodein classRubyObject- Returns:
- the hash code
- See Also:
-
toString
Description copied from class:RubyObjectThe default toString method is just a wrapper that calls the Ruby "to_s" method.- Overrides:
toStringin classRubyObject- Returns:
- string representation
-
lock
Acquire the given lock, holding a reference to it for cleanup on thread termination.- Parameters:
lock- the lock to acquire, released on thread termination
-
lockInterruptibly
Acquire the given lock interruptibly, holding a reference to it for cleanup on thread termination.- Parameters:
lock- the lock to acquire, released on thread termination- Throws:
InterruptedException- if the lock acquisition is interrupted
-
tryLock
Try to acquire the given lock, adding it to a list of held locks for cleanup on thread termination if it is acquired. Return immediately if the lock cannot be acquired.- Parameters:
lock- the lock to acquire, released on thread termination
-
unlock
Release the given lock and remove it from the list of locks to be released on thread termination.- Parameters:
lock- the lock to release and dereferences
-
unlockAll
public void unlockAll()Release all locks held. -
sleep
Release lock and sleep.- Throws:
InterruptedException
-
sleep
Release lock and sleep for the specified number of milliseconds.- Throws:
InterruptedException
-
toJava
Customized for retrieving a Java thread from a Ruby one.- Specified by:
toJavain interfaceIRubyObject- Overrides:
toJavain classRubyBasicObject- Type Parameters:
T- type- Parameters:
target- The target type to which the object should be converted (e.g.java.lang.Thread.class).- Returns:
- java type
- Since:
- 9.4
- See Also:
-
uninterruptible
public static <StateType> IRubyObject uninterruptible(ThreadContext context, StateType state, BiFunction<ThreadContext, StateType, IRubyObject> f) Run the providedBiFunctionwithout allowing for any cross-thread interrupts (equivalent to callinghandle_interrupt(ThreadContext, IRubyObject, IRubyObject, Block)with Object => :never. MRI: rb_uninterruptible- Parameters:
context- the current contextf- the bifunction to execute- Returns:
- return value of f.apply.
-
setFiberScheduler
Deprecated. -
setFiberScheduler
Set the scheduler for the current thread. MRI: rb_fiber_scheduler_set -
getScheduler
-
getSchedulerCurrent
-
incrementBlocking
public void incrementBlocking() -
decrementBlocking
public void decrementBlocking() -
isBlocking
public boolean isBlocking() -
pending_interrupt_p
Deprecated. -
pending_interrupt_p
@Deprecated public static IRubyObject pending_interrupt_p(ThreadContext context, IRubyObject self, IRubyObject[] args) Deprecated. -
alive_p
Deprecated. -
value
Deprecated. -
join
Deprecated. -
op_aset
Deprecated.
-