Struct rust_jni::JavaVM [−][src]
pub struct JavaVM { /* fields omitted */ }
A struct for interacting with the Java VM.
Examples
use rust_jni::{InitArguments, JavaVM, JniVersion, JvmOption, JvmVerboseOption}; use std::ptr; let options = InitArguments::get_default(JniVersion::V8).unwrap() .with_option(JvmOption::Verbose(JvmVerboseOption::Gc)) .with_option(JvmOption::Verbose(JvmVerboseOption::Jni)); let vm = JavaVM::create(&options).unwrap(); unsafe { assert_ne!(vm.raw_jvm(), ptr::null_mut()); } let vms = JavaVM::list().unwrap(); unsafe { assert_eq!(vms[0].raw_jvm(), vm.raw_jvm()); }
JavaVM
is Send + Sync
. It means it can be shared between threads.
use rust_jni::{InitArguments, JavaVM, JniVersion}; use std::ptr; use std::sync::Arc; let vm = Arc::new(JavaVM::create(&InitArguments::get_default(JniVersion::V8).unwrap()).unwrap()); { let vm = vm.clone(); ::std::thread::spawn(move || { unsafe { assert_ne!(vm.raw_jvm(), ptr::null_mut()); } }); } unsafe { assert_ne!(vm.raw_jvm(), ptr::null_mut()); }
The main purpose of JavaVM
is to attach threads by provisioning
JniEnv
-s.
Methods
impl JavaVM
[src]
impl JavaVM
pub fn create(arguments: &InitArguments) -> Result<Self, JniError>
[src]
pub fn create(arguments: &InitArguments) -> Result<Self, JniError>
Create a Java VM with the specified arguments.
Only one Java VM per process is supported. When called for the second time will return an error. This is the case even if the object is dropped.
pub fn list() -> Result<Vec<Self>, JniError>
[src]
pub fn list() -> Result<Vec<Self>, JniError>
Get a list of created Java VMs.
pub unsafe fn raw_jvm(&self) -> *mut JavaVM
[src]
pub unsafe fn raw_jvm(&self) -> *mut JavaVM
Get the raw Java VM pointer.
This function provides low-level access to all of JNI and thus is unsafe.
pub fn attach(&self, arguments: &AttachArguments) -> Result<JniEnv, JniError>
[src]
pub fn attach(&self, arguments: &AttachArguments) -> Result<JniEnv, JniError>
Attach the current thread to the Java VM with a specific thread name.
Returns a JniEnv
instance for this thread.
pub fn attach_daemon(
&self,
arguments: &AttachArguments
) -> Result<JniEnv, JniError>
[src]
pub fn attach_daemon(
&self,
arguments: &AttachArguments
) -> Result<JniEnv, JniError>
Attach the current thread to the Java VM as a daemon with a specific thread name.
Returns a JniEnv
instance for this thread.
Trait Implementations
impl Debug for JavaVM
[src]
impl Debug for JavaVM
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Drop for JavaVM
[src]
impl Drop for JavaVM
Make JavaVM
be destroyed when the value is dropped.
impl Send for JavaVM
[src]
impl Send for JavaVM
Make JavaVM
sendable between threads. Guaranteed to be safe by JNI.
impl Sync for JavaVM
[src]
impl Sync for JavaVM
Make JavaVM
shareable by multiple threads. Guaranteed to be safe
by JNI.