Example #1
0
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);
      }
    }
Example #2
0
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 {
      }
    }
Example #3
0
static THREAD_SPECIFIC_DATA_NEW(tsdJavaNativeThread) {
  return getJavaInvocationInterface();
}