T
Tim Ward
When a Java application makes multiple calls into a DLL via JNI for the same
Java object, what's the conventional idiom for the DLL to store state
relating to the Java object, where there is no reason to expose the DLL's
state information to the Java code (other than via the JNI calls) and where
calls into the DLL relating to the same object will be from different
threads (if that makes a difference)?
(1) Does the DLL keep a map from the passed "jobject" to its private data?
Does that work? - is the passed "jobject" the same every time the DLL is
called in relation to the same Java object (regardless of thread and garbage
collection history)? If you do this how do you know when the Java object has
gone away so as to release the state in the DLL?
(2) Does the DLL store a pointer to its state in, say, an integer member in
the Java object, which the Java code promises not to look at? Again, in this
case how does the DLL know when the Java object has gone away so as to be
able to release the state?
(3) Given that the above two both sound unsatisfactory, how do people really
do it?
Java object, what's the conventional idiom for the DLL to store state
relating to the Java object, where there is no reason to expose the DLL's
state information to the Java code (other than via the JNI calls) and where
calls into the DLL relating to the same object will be from different
threads (if that makes a difference)?
(1) Does the DLL keep a map from the passed "jobject" to its private data?
Does that work? - is the passed "jobject" the same every time the DLL is
called in relation to the same Java object (regardless of thread and garbage
collection history)? If you do this how do you know when the Java object has
gone away so as to release the state in the DLL?
(2) Does the DLL store a pointer to its state in, say, an integer member in
the Java object, which the Java code promises not to look at? Again, in this
case how does the DLL know when the Java object has gone away so as to be
able to release the state?
(3) Given that the above two both sound unsatisfactory, how do people really
do it?