how to cache the env and obj variables in JNI

M

marydeepthy

Hi,

i have a native method, from where a call to java method has to me
made.

but my problem is, my java method ConnectionIndication does not make a
call to my native method native_ConnectionIndication.
but this java method makes another native calls.so can i cache that env
and obj variables.

Regards

Mary Deepthy
 
M

marydeepthy

the problem i face is , since the java method does not make a call to
native_ConnectionIndication, i dont have env and obj variables in my
native method. but the same java class makes another native calls...so
i want to cache that env and obj variables. what shall i do.
 
G

Gordon Beaton

the problem i face is , since the java method does not make a call
to native_ConnectionIndication, i dont have env and obj variables in
my native method. but the same java class makes another native
calls...so i want to cache that env and obj variables. what shall i
do.

Do not attempt to cache the JNIEnv* in any way! If you need to use a
JNIEnv* in a context where it wasn't passed directly to you from the
JVM, request one with GetEnv(), AttachCurrentThread() or
AttachCurrentThreadAsDaemon().

To cache a jobject reference, first use NewGlobalRef() to ensure that
the object it refers to does not become eligible for garbage
collection. Store the resulting global reference however you like, for
example in a global static variable in your native code. Don't forget
to use DeleteGlobalRef() when you no longer need the object.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top