您可以在单个进程中在JNI中创建多个JVM吗? [英] Can you create multiple JVMs in JNI in a single process?

查看:137
本文介绍了您可以在单个进程中在JNI中创建多个JVM吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++框架,该框架在单个进程中运行并允许使用模块,而我想添加的一种类型的模块是加载JAR,然后在其中调用特定预定义函数的模块.可以根据用户的需要同时运行多个模块,这引发了一个问题:

I have a C++ framework that runs in a single process and allows for modules, and one type of module I would like to add is a module that loads a JAR and then calls a specific predefined function in it. There can be as many modules running simultaneously as the user desires, which raises the question:

每个模块都可以使用JNI_CreateJavaVM()创建一个单独的JVM,并且那些JVM将完全彼此独立(但是在同一过程中)吗?还是Java在内部依赖于全局变量等会使它们相互干扰?

Could each module create a separate JVM with JNI_CreateJavaVM() and those JVMs would be entirely independent of each other (however in the same process)? Or is Java internally relying on globals etc that would make them interfere with each other?

推荐答案

仅允许您在每个进程中创建一个VM,并获得一个JNIEnv.某些非常老的JVM实现曾经支持创建多个VM,但现在不再支持.

You are only allowed to create a single VM in each process, and get a single JNIEnv. Creation of multiple VMs was once supported in some very old JVM implementations, but no longer is.

请参见Oracle

See JNI_CreateJavaVM in Oracle's Java 7 JNI documentation:

从JDK/JRE 1.2开始,不支持在单个进程中创建多个VM.

As of JDK/JRE 1.2 , creation of multiple VMs in a single process is not supported.

IBM的JDK 7 JNI文档:

IBM i上的Java仅支持在单个作业或流程中创建一个Java虚拟机(JVM).

Java on IBM i supports creating only one Java virtual machine (JVM) within a single job or process.

(通常,IBM AIX JVM具有相同的限制)

更详细地此处:

您不能在一个作业中多次成功调用JNI_CreateJavaVM(),并且JNI_GetCreatedJavaVMs()不能在结果列表中返回多个JVM.

You cannot successfully call JNI_CreateJavaVM() more than once in a job, and JNI_GetCreatedJavaVMs() cannot return more than one JVM in a list of results.

仅在单个作业或流程中创建单个JVM的支持遵循Oracle America,Inc. Java参考实现的标准.

Support for creating only a single JVM within a single job or process follows the standards of the Oracle America, Inc. reference implementation of Java.

这篇关于您可以在单个进程中在JNI中创建多个JVM吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆