
Dans le même programme C++ je n'arrive pas à ouvrir successivement deux JVM.
La première fois ça se passe très bien, la seconde ça échoue lamentablement.
Voici le test case :
for ( int i= 0 ; i < 2 ; ++i ) {
const int nbOptions= 1 ;
JavaVMOption* optionsJVM(new JavaVMOption[nbOptions]) ;
optionsJVM[0].optionString= "-Djava.class.path=C:/.../class" ;
optionsJVM[0].extraInfo= NULL ;
JavaVMInitArgs vm_args ; /* JDK/JRE 6 VM initialization arguments */
vm_args.version= JNI_VERSION_1_6 ;
vm_args.nOptions= nbOptions ;
vm_args.options= optionsJVM ;
vm_args.ignoreUnrecognized= false ;
/* load and initialize a Java VM, return a JNI interface pointer in jniEnv */
union {
void* voidEnv ;
JNIEnv* jniEnv ;
} env ;
JavaVM* jvm ;
jint ret= JNI_CreateJavaVM(&jvm, &(env.voidEnv), &vm_args) ;
delete[] optionsJVM ;
std::cout << "JNI_CreateJavaVM status: " << (ret==JNI_OK?"success":"fail") << " (ret=" << ret << ")" << std::endl ;
if ( ret == JNI_OK ) {
jint retDestroy= jvm->DestroyJavaVM() ;
std::cout << "DestroyJavaVM status: " << (retDestroy==0?"success":"fail") << " (retDestroy=" << retDestroy << ")" << std::endl ;
}
}us: fail (ret=-1)
et le résultat : JNI_CreateJavaVM status: success (ret=0) DestroyJavaVM status: success (retDestroy=0) JNI_CreateJavaVM stat
Je sais qu'on ne peut pas créer plus d'une VM dans un processus, mais en la détruisant avant d'en faire une autre, ça devrait passer, non ? Toutefois, d'après http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/invocation.html#destroy_java_vm, c'est pas très clair si la destruction est vraiment implémentée ou pas... (je suis en JAVA 6)
The JDK/JRE still does not support VM unloading, however.Enfin, à la rigueur, si, c'est clair mais ça me parait étrange que ça ne soit vraiment pas supporté

Avez-vous de l'expérience sur ce point ?
Du coup, je pense que je vais n'en créer qu'une seule, la laisser vivre (dans une DLL) et m'arranger avec un attachCurrentThread().
Est-ce bien ce qu'il faut faire ?
Merci d'avance



(du moins je crois, en tout cas ça ne rend pas la main au VB)