[−][src]Struct jni::Executor
Thread attachment manager. It allows to execute closures in attached threads with automatic
local references management done with with_local_frame
. It combines the performance benefits
of permanent attaches whilst removing the risk of local references leaks if used consistently.
Although all locals are freed on closure exit, it might be needed to manually free locals inside the closure if an unbounded number of them is created (e.g., in a loop). See "Local Reference Management" for details.
Threads using the Executor are attached on the first invocation as daemons, hence they do not block JVM exit. Finished threads detach automatically.
Example
let exec = Executor::new(jvm); let val: jint = exec.with_attached(|env| { let x = JValue::from(-10); let val: jint = env.call_static_method("java/lang/Math", "abs", "(I)I", &[x])? .i()?; Ok(val) })?; assert_eq!(val, 10);
Methods
impl Executor
[src]
pub fn new(vm: Arc<JavaVM>) -> Self
[src]
Creates new Executor with specified JVM.
pub fn with_attached_capacity<F, R>(&self, capacity: i32, f: F) -> Result<R> where
F: FnOnce(&JNIEnv) -> Result<R>,
[src]
F: FnOnce(&JNIEnv) -> Result<R>,
Executes a provided closure, making sure that the current thread is attached to the JVM. Additionally ensures that local object references are freed after call.
Allocates a local frame with the specified capacity.
pub fn with_attached<F, R>(&self, f: F) -> Result<R> where
F: FnOnce(&JNIEnv) -> Result<R>,
[src]
F: FnOnce(&JNIEnv) -> Result<R>,
Executes a provided closure, making sure that the current thread is attached to the JVM. Additionally ensures that local object references are freed after call.
Allocates a local frame with the default capacity.
Trait Implementations
Auto Trait Implementations
impl Send for Executor
impl Sync for Executor
impl Unpin for Executor
impl UnwindSafe for Executor
impl RefUnwindSafe for Executor
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,