Making JNIEnv a global reference

Hi All,

I have a class A in which I have a method m1() and a static method m2(). From m1() I invoke a native method nm1() passing refernce to the JNIEnv and other parameters. When there is a call to nm1(), the control goes to nm2 another native method. From nm2, I need to make a call back method on class A to invoke m2(). Please note that I cannot pass JNIEnv reference to nm2(). Can I make the incoming JNIEnv inside nm1() a global reference and access it from nm2()? Also note that i will only make use of JNIEnv and not the jObject in the nm2(). I know it works but would like to know what would be the impact in the multi threaded scenario.

Any inputs in this regard would be greatly apprciated.

Thanks,

Griish

[747 byte] By [GirishK_12a] at [2007-11-26 17:26:12]
# 1

Hi,

I think you should save the JavaVM* pointer then get back the JNIEnv* from it.

See the callback part of JNative at http://jnative.cvs.sourceforge.net/jnative/JNativeCpp/CallBack.cpp?view=markup

As you can see at line 11 the JNIEnv got from the vm pointer.

I choose to save the JavaVM* pointer for potential threading issues.

--Marc (http://jnative.sf.net)

mdentya at 2007-7-8 23:54:14 > top of Java-index,Java HotSpot Virtual Machine,Specifications...