pub struct Thread { /* private fields */ }Expand description
A thread is a single sequential flow of control within a program. It has its own call stack and program counter.
§References
Implementations§
Source§impl Thread
impl Thread
Sourcepub async fn java_object(&self) -> Value
pub async fn java_object(&self) -> Value
Get the Java object for this thread.
Sourcepub async fn set_java_object(&self, new_java_object: Value)
pub async fn set_java_object(&self, new_java_object: Value)
Set the Java thread object for this thread.
Sourcepub async fn current_frame(&self) -> Result<Arc<Frame>>
pub async fn current_frame(&self) -> Result<Arc<Frame>>
Sourcepub fn is_interrupted(&self, clear_interrupt: bool) -> bool
pub fn is_interrupted(&self, clear_interrupt: bool) -> bool
Check if the thread is interrupted and clear the interrupt if specified.
Sourcepub async fn sleep(&self, duration: Duration) -> bool
pub async fn sleep(&self, duration: Duration) -> bool
Sleep the thread for the specified duration. The sleep is interruptible - if another
thread calls interrupt(), this method will return true to indicate the thread was
interrupted, clearing the interrupt flag.
§Arguments
duration- The duration to sleep.
§Returns
Returns true if the sleep was interrupted, false if it completed normally.
Sourcepub async fn park(&self, is_absolute: bool, time: u64) -> Result<()>
pub async fn park(&self, is_absolute: bool, time: u64) -> Result<()>
Park the thread. If the permit is available, it will be consumed and the thread will return immediately. If the permit is not available, the thread will be parked until it is unparked or the specified time has elapsed.
§Arguments
is_absolute- If true, thetimeparameter is treated as an absolute timestamp (milliseconds since epoch).time- The time to park the thread. Ifis_absoluteis true, this is the absolute timestamp in milliseconds since epoch. Ifis_absoluteis false, this is the relative duration in nanoseconds.
§Errors
If the parking operation fails, an error will be returned.
Sourcepub fn class<'life_self, 'async_recursion, S>(
&'life_self self,
class_name: S,
) -> Pin<Box<dyn Future<Output = Result<Arc<Class>>> + Send + 'async_recursion>>
pub fn class<'life_self, 'async_recursion, S>( &'life_self self, class_name: S, ) -> Pin<Box<dyn Future<Output = Result<Arc<Class>>> + Send + 'async_recursion>>
Get a class and ensure it is initialized.
This implements the class initialization procedure as specified in JLS §12.4.2:
- If the class is already initialized, return immediately
- If the class is in an erroneous state, throw
NoClassDefFoundError - If the class is being initialized by the current thread, return (recursive initialization)
- If the class is being initialized by another thread, wait and recheck
- Mark the class as being initialized by the current thread
- Initialize the direct superclass first (recursive)
- Execute
<clinit>for this class - If
<clinit>throws, mark as Erroneous and throwExceptionInInitializerError - Mark the class as Initialized
Note: This implementation does NOT initialize interfaces as part of class initialization unless explicitly triggered per JLS §12.4.1.
§References
§Errors
if the class cannot be loaded or initialized
Sourcepub async fn invoke<C, M>(
&self,
class: C,
method: M,
parameters: &[impl RustValue],
) -> Result<Option<Value>>
pub async fn invoke<C, M>( &self, class: C, method: M, parameters: &[impl RustValue], ) -> Result<Option<Value>>
Invoke a method. To invoke a method on an object reference, the object reference must be the first parameter in the parameters vector.
§Errors
if the method cannot be invoked
Sourcepub async fn try_invoke<C, M>(
&self,
class: C,
method: M,
parameters: &[impl RustValue],
) -> Result<Value>
pub async fn try_invoke<C, M>( &self, class: C, method: M, parameters: &[impl RustValue], ) -> Result<Value>
Invoke a method. To invoke a method on an object reference, the object reference must be the first parameter in the parameters vector.
§Errors
if the method cannot be invoked
Sourcepub async fn execute(
&self,
class: &Arc<Class>,
method: &Arc<Method>,
parameters: &[impl RustValue],
) -> Result<Option<Value>>
pub async fn execute( &self, class: &Arc<Class>, method: &Arc<Method>, parameters: &[impl RustValue], ) -> Result<Option<Value>>
Add a new frame to the thread and invoke the method. To invoke a method on an object reference, the object reference must be the first parameter in the parameters vector.
§Errors
if the method cannot be invoked.
Sourcepub async fn try_execute(
&self,
class: &Arc<Class>,
method: &Arc<Method>,
parameters: &[impl RustValue],
) -> Result<Value>
pub async fn try_execute( &self, class: &Arc<Class>, method: &Arc<Method>, parameters: &[impl RustValue], ) -> Result<Value>
Add a new frame to the thread and invoke the method. To invoke a method on an object reference, the object reference must be the first parameter in the parameters vector.
§Errors
if the method cannot be invoked.
Trait Implementations§
Source§impl Thread for Thread
impl Thread for Thread
Source§fn java_object(&self) -> BoxFuture<'_, Value>
fn java_object(&self) -> BoxFuture<'_, Value>
Source§fn set_java_object(&self, value: Value) -> BoxFuture<'_, ()>
fn set_java_object(&self, value: Value) -> BoxFuture<'_, ()>
Source§fn frames(&self) -> BoxFuture<'_, Result<Vec<Arc<Frame>>>>
fn frames(&self) -> BoxFuture<'_, Result<Vec<Arc<Frame>>>>
Source§fn is_interrupted(&self, clear_interrupt: bool) -> bool
fn is_interrupted(&self, clear_interrupt: bool) -> bool
Source§fn sleep(&self, duration: Duration) -> BoxFuture<'_, bool>
fn sleep(&self, duration: Duration) -> BoxFuture<'_, bool>
true if the sleep was interrupted.Source§fn park(&self, is_absolute: bool, time: u64) -> BoxFuture<'_, Result<()>>
fn park(&self, is_absolute: bool, time: u64) -> BoxFuture<'_, Result<()>>
Source§fn class<'a>(&'a self, class_name: &'a str) -> BoxFuture<'a, Result<Arc<Class>>>
fn class<'a>(&'a self, class_name: &'a str) -> BoxFuture<'a, Result<Arc<Class>>>
Source§fn load_and_link_class<'a>(
&'a self,
class_name: &'a str,
) -> BoxFuture<'a, Result<Arc<Class>>>
fn load_and_link_class<'a>( &'a self, class_name: &'a str, ) -> BoxFuture<'a, Result<Arc<Class>>>
Source§fn register_class(&self, class: Arc<Class>) -> BoxFuture<'_, Result<()>>
fn register_class(&self, class: Arc<Class>) -> BoxFuture<'_, Result<()>>
Source§fn invoke<'a>(
&'a self,
class: &'a str,
method: &'a str,
parameters: &'a [Value],
) -> BoxFuture<'a, Result<Option<Value>>>
fn invoke<'a>( &'a self, class: &'a str, method: &'a str, parameters: &'a [Value], ) -> BoxFuture<'a, Result<Option<Value>>>
Source§fn try_invoke<'a>(
&'a self,
class: &'a str,
method: &'a str,
parameters: &'a [Value],
) -> BoxFuture<'a, Result<Value>>
fn try_invoke<'a>( &'a self, class: &'a str, method: &'a str, parameters: &'a [Value], ) -> BoxFuture<'a, Result<Value>>
Source§fn execute<'a>(
&'a self,
class: &'a Arc<Class>,
method: &'a Arc<Method>,
parameters: &'a [Value],
) -> BoxFuture<'a, Result<Option<Value>>>
fn execute<'a>( &'a self, class: &'a Arc<Class>, method: &'a Arc<Method>, parameters: &'a [Value], ) -> BoxFuture<'a, Result<Option<Value>>>
Source§fn try_execute<'a>(
&'a self,
class: &'a Arc<Class>,
method: &'a Arc<Method>,
parameters: &'a [Value],
) -> BoxFuture<'a, Result<Value>>
fn try_execute<'a>( &'a self, class: &'a Arc<Class>, method: &'a Arc<Method>, parameters: &'a [Value], ) -> BoxFuture<'a, Result<Value>>
Auto Trait Implementations§
impl !Freeze for Thread
impl !RefUnwindSafe for Thread
impl Send for Thread
impl Sync for Thread
impl Unpin for Thread
impl !UnwindSafe for Thread
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more