invoke methods at defered time - timing problems

Hello !

My C code contains two functions to implement JNI for Java methods invocation :

- InitFunction loads JVM and stores class to call :

{

JNI_CreateJavaVM(...)

cls= ...->FindClass(...)

/* g_cls is a global variable */

g_cls = ...->NewGlobalRef(..., cls)

/* g_myMethod is a global variable */

g_myMethodID = ->GetStaticMethodID(..., g_cls, method, ...)

}

- CallFunction invokes java method

{

...

...->CallStaticVoidMethod( ..., g_cls, g_myMethodID, args ) ;

}

When CallFunction is run inside InitFunction, no problem occurs.

But when it is called later, it doesn't, raising a error.

Do I have to store jni-environment variable in a global reference, I can I do this?

Thank you for help!

JCC

[841 byte] By [jccarrion] at [2007-9-26 6:33:01]
# 1

The jvm either has to exists or has to be created.

The proper way to do this depends on your application.

If you want the same jvm then you should keep an instance somewhere or use the JNI method that returns the current JVM (it actually returns an array but only the first array index has anything.) This means that you should also plan on terminating the jvm sometime also.

jschell at 2007-7-1 15:44:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

I agree with you !

Maybe my code example was not clear, but I actually store data filled by "JNI_CreateJavaVM" function in global variables. But I wonder whether they are still available when I use them, later, in a further run function.

I can't know if my problem comes from JVM availability!

thanks

JCC

jccarrion at 2007-7-1 15:44:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...