I have a C method that is called from a Java process:
extern "C" {
JNIEXPORT jstring JNICALL Java_bla_bla_bla(JNIEnv *env, jclass java_class, jint param) {
/* Spawn C threads that are going to call Java methods */
}
}
The problem is that all what my native method gets from Java is a JNIEnv
instance. In order to call AttachCurrentThread()
, I need a JavaVM
object.
How can I get the JavaVM
pointer from my native method?
One alternative is to cache the
JavaVM*
you receive inJNI_OnLoad
.Another alternative is to call the
GetJavaVM
function that is part of theJNIEnv
: