Reputation: 215
I have some java code that calls a jni layer.
The JNI layer is a 3rd party so I can't inspect it, but at some point it creates a new thread and makes a callback to the java code.
Inside this callback method I try to create another java thread and call start on the thread. However this java thread never gets run. Its like it never exists.
Is creating threads from JNI call backs a problem ?
I can create a threadpoolexecutor with a core size and put the task on the executor instead but I'd like to know why I can't create threads inside the callback.
Upvotes: 1
Views: 1523
Reputation: 310936
You need to call AttachCurrentThread()
inside the callback before it calls any other JNI method, and DetachCurrentThread()
before it exits.
Upvotes: 3