Search This Blog

Wednesday, July 17, 2019

JNI calls in Multi-thread application (or call back from java to C++ )

When you try to accee
Recently i noticed when i tried to access my global JNIEnv  from other thread ( not the one who initialize it) , i get failed to call to FindClass.

from the document :
"The JNI interface pointer (JNIEnv) is valid only in the current thread"

so you must call to AttachCurrentThread() method first on the new thread, and detach it via DetachCurrentThread()

you can read more about it at 
The Invocation API



enjoy
Yaniv Tzanany

No comments: