Struct rust_jni::JavaVM[][src]

pub struct JavaVM { /* fields omitted */ }

A struct for interacting with the Java VM.

JNI documentation

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]

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.

JNI documentation

Get a list of created Java VMs.

JNI documentation

Get the raw Java VM pointer.

This function provides low-level access to all of JNI and thus is unsafe.

Attach the current thread to the Java VM with a specific thread name. Returns a JniEnv instance for this thread.

JNI documentation

Attach the current thread to the Java VM as a daemon with a specific thread name. Returns a JniEnv instance for this thread.

JNI documentation

Trait Implementations

impl Debug for JavaVM
[src]

Formats the value using the given formatter. Read more

impl Drop for JavaVM
[src]

Make JavaVM be destroyed when the value is dropped.

JNI documentation

Executes the destructor for this type. Read more

impl Send for JavaVM
[src]

Make JavaVM sendable between threads. Guaranteed to be safe by JNI.

impl Sync for JavaVM
[src]

Make JavaVM shareable by multiple threads. Guaranteed to be safe by JNI.