JNIEnv * getJavaNativeInterface (void) { JNIEnv *env = NULL; JavaVM *vm = getJavaInvocationInterface(); if (vm) { jint result = (*vm)->GetEnv(vm, (void **)&env, JAVA_JNI_VERSION); if (result != JNI_OK) { if (result == JNI_EDETACHED) { JavaVMAttachArgs args = { .version = JAVA_JNI_VERSION, .name = NULL, .group = NULL }; if ((result = (*vm)->AttachCurrentThread(vm, &env, &args)) < 0) { logMessage(LOG_WARNING, "Java AttachCurrentThread error: %d", result); } else { logMessage(LOG_DEBUG, "thread attached to Java VM"); getThreadSpecificData(&tsdJavaNativeThread); } } else { logMessage(LOG_WARNING, "Java GetEnv error: %d", result); } }
JNIEnv * getJavaNativeInterface (void) { JNIEnv *env = NULL; JavaVM *vm = getJavaInvocationInterface(); if (vm) { jint result = (*vm)->GetEnv(vm, (void **)&env, JAVA_JNI_VERSION); if (result != JNI_OK) { if (result == JNI_EDETACHED) { JavaVMAttachArgs args = { .version = JAVA_JNI_VERSION, .name = NULL, .group = NULL }; if ((result = (*vm)->AttachCurrentThread(vm, &env, &args)) < 0) { } else { pthread_once(&threadDetachHandlerOnce, createThreadDetachHandlerKey); pthread_setspecific(threadDetachHandlerKey, vm); } } else { } }
static THREAD_SPECIFIC_DATA_NEW(tsdJavaNativeThread) { return getJavaInvocationInterface(); }