After creating and destroing VM you can't create it once more. JNI spec unclear in this case. It states restriction in JDK version 1.1 only, and say nothing about other versions. "One process - one VM" is a good rule, but what is about successive creation/destroing of VM?
#include <jni.h>
#include <signal.h>
#include <stdio.h>
static JNIEnv *env;
static JavaVM *vm;
void initVM()
{
vm = 0;
env = 0;
JavaVMInitArgs vm_args;
JavaVMOption opt[2];
opt[0].optionString = "-verbose:jni";
opt[1].optionString = "-Xcheck:jni";
vm_args.nOptions = 2;
vm_args.version = JNI_VERSION_1_4;
vm_args.ignoreUnrecognized = JNI_TRUE;
vm_args.options = opt;
jint result = JNI_CreateJavaVM( &vm, (void **) &env, &vm_args );
if (result != 0) {
printf("# ERROR: cannot create Java VM. %d\n", result);
exit(result);
}
//(*vm)->AttachCurrentThread(vm, (void **) &env, (void *) 0);
printf("JVM started and attached\n");
result = (*vm)->DestroyJavaVM(vm);
if (result != 0) {
printf("# ERROR: cannot destroy Java VM. %d\n", result);
exit(result);
}
}
int main(int argc, char **argv)
{
int i;
for (i = 0; i < 1000; ++i)
initVM();
return 0;
}
###@###.### 2005-06-09 17:12:50 GMT