Hi,
On Jul 6, 10:22 pm, fadden <
fad...@android.com> wrote:
>
> Well, that's a new one. Somehow the JNIEnv is being shared between
> threadid=3 (the main thread) and threadid=5 (the HeapWorker or
> "finalizer" thread). Except that doesn't really make sense, since the
> HeapWorker stack trace doesn't show any activity. Maybe the thread-
> local storage got tangled up?
I just read the android jni tips located here :
and here is a quote from that document:
On some VMs, the JNIEnv is used for thread-local storage. For this
reason, you cannot share a JNIEnv between threads. If a piece of code
has no other way to get its JNIEnv, you should share the JavaVM, and
use JavaVM->GetEnv to discover the thread's JNIEnv.
At the moment, I am caching the JNIEnv obtained from a device.open()
method in the device client.java project. Then this JNIEnv pointer is
being cached in the device c callback method, and each time the
callback gets invoked when some new data is available, I am using the
JNIEnv pointer to invoke the java callback to notify the device.java
component that some data is available to be read and handled.
So, after 4 or 5 calls, the garbage collector gets invoked, and then
the system crashes.
Does invocation of the garbage collector somehow change the JNIEnv
pointer?
I've posted a separate thread to find out how to obtain the JavaVM in
my jni cpp code, so that I can use that to obtain the JNIEnv pointer
each time the jni cpp callback needs to invoke the java callback
method.
Best regards,
Elvis