multiple threads and JNIEnv problem
843829Aug 9 2005 — edited Aug 11 2005I am preparing a c++ dll that will be used by a peer group. This c++ dll is invoking a jvm inside via jni.
Now, I do not know how the peer group will use my c++ dll objects. i.e. they can be used in multiple threads. Currently, I am caching the jni implementation (jobject, jclass, jenv, jvm) within each c++ dll object.
Since the jenv needs to be different for each thread, I am thinking of preparing a map that has a threadID---jenv mapping. So, each object before invoking any of its methods can get the appropriate jenv based on the thread it is in.
I know that this is more of a design question, but this seems to be a common problem and l welcome all the "pearls of wisdom" from our jni gurus.
thanks in advance
Hitendra Gupta