I have the below function 'initializeAlgo' that is used to initialize the Java VM with a specific Algo jar file and later I use the java environment created to call other fns in the Jar.
JavaVM *jvm;
JNIEnv *env;
void initializeAlgo(const std::string& algoSourceJar) {
JavaVMInitArgs vm_args;
JavaVMOption* options = new JavaVMOption[1];
std::string classPath = "-Djava.class.path=" + algoSourceJar;
options[0].optionString = new char[classPath.length()]();
strcpy(options[0].optionString, classPath.c_str());
vm_args.version = JNI_VERSION_1_6;
vm_args.nOptions = 1;
vm_args.options = options;
vm_args.ignoreUnrecognized = false;
//================= load and initialize Java VM and JNI interface============
initStatus = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
}
Suppose If i have to support dynamic loading of multiple Algo sources that satisfy a certain interface. i.e. load Algo_1 and do some process and record results, and without closing the application I want to load Algo_2 and do the same process and record results. And they both have the same namespace and fns. Is it recommended to do this in the same instance of the application?