JNI - multi threads

前端 未结 1 1441
梦谈多话
梦谈多话 2021-01-04 11:57

I have a JNI wrapper for Java functions that are called from C... I\'m trying to call some methods from different threads and I get an error when trying to get a new copy o

1条回答
  •  北荒
    北荒 (楼主)
    2021-01-04 12:14

    Please refer to the documentation to the chapter Attaching to the VM.

    You need to call AttachCurrentThread() for each native thread at least once before you can use any of the JNI functions.
    Thread created in Java are already attached.
    So I your example whenever the GetEnv call fails call AttachCurrentThread() and you should be fine. Or make sure that whenver you create a sub thread you attach it to the VM.

    0 讨论(0)
提交回复
热议问题