Reputation: 1311
I'm using a library that calls the JNI_CreateJavaVM
function inside the library code. However, I also need some JNI Wrappings and I need to call the same function JNI_CreateJavaVM
to get the JNIEnv*
to my application.
But the second call is failing.
is there any way to do this?
The library does not support getting or setting the JNIEnv*
created inside the library.
Upvotes: 3
Views: 857
Reputation: 3731
You cannot create more than one JVM from the same process:
As of JDK/JRE 1.2 , creation of multiple VMs in a single process is not supported.
You may be able to attach your current thread to the existing JVM though using AttachCurrentThread
function. See the docs for the Invocation API. The equivalent document in Java 15 simply states:
Creation of multiple VMs in a single process is not supported.
You will need a pointer to the JavaVM
object. See if JNI_GetCreatedJavaVMs()
can help you, I'm not sure if this is per-process (in which case it will only ever be a single element list) or per machine. In either case the JavaVM
will have to be the one that the library is using or you probably will not be doing what you want. If you can access that then you should be able to make invocations on other objects in your Java application, but make sure that it is thread-safe.
Upvotes: 5