Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Lifetime of JNI objects between calls.

843829Jul 24 2001 — edited Aug 8 2003
Is it possible to store/cache non-class JNI objects between calls?

I know I can 'lock' jclass object to *env however I need to be able to do more than this.

Implementation :

C++ code for which I am not responsible for NOR will I ever get access to the source code needs to be built into a Java Application.

Everything that I need to do works fine except when I need to have jobject's and, in particular, the JNIEnv reference to be cached in the dll between JNI calls.

Raison d'etre : I want to implement a Callback using a Java object (Observer/Observable) so that the status of the C legacy app can be monitored via a callback implemented as part of the dll.

Java object is called via the C callback, sets status via a status method called via JNI, Java App is notifoed of the change.

Problem, as long as the first call the the jobject occurs within the actual JNI call that creates the Java object all is well, as soon as I try and store the jobject and JNIEnv references so that the C callback can call it as well then things break.

Is it possible to have JNI objects whose lifetime spans JNI calls at all?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 5 2003
Added on Jul 24 2001
9 comments
1,101 views