一个进程只允许创建一个虚拟机,而java虚拟机的退出机制有事非强制性的。所以创建失败,后去尝试获取本进程已有虚拟机。
JavaVM *jvm; JavaEnv *env; JavaVMOption option[3]; option[0].optionString = "-Djava.complier=NONE"; option[1].optionString = "-Djava.class.path=./:.my.jar"; option[2].optionString = "-Djava.library.path=/my/path"; vm_args.version = JNI_VERSION_1_8; vm_args.ignoreUnrecognized = JNI_TRUE; vm_args.nOption = 3; vm_args.options = options; long Status = JNI_CreateJavaVM( &jvm, (void**)&env, &VM_args ); if( status < 0 || status == JNI_ERR ){ jint count = 0; jint result = JNI_GetCreatedJavaVMs( &jvm,sizeof(JavaVM)*10, &count ); if( result != JNI_OK ){ printf("获取jvm失败n"); return -1; } jint result1 = (*jvm)->GetEnv( jvm, (void**)&env, JNI_VERSION_1_8 ); if( result1 != JNI_OK ){ printf("获取env失败n"); return -1; } jint2 result2 = (*env)->GetJavaVM( env, &jvm ); if( result2 != JNI_OK ){ printf("获取虚拟机失败n"); return -1; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)