stop native call from java
I know there are topics related to timeout, stop or kill native call but it seems there is no good answer for me.
I have a java class as the caller to call a native C function with double arrays as input. The C function perform some kind of computation using 3rd party FORTRAN functions. If we terminate the java, how to terminate/stop/or exit the C function?
Here is the partial of java class
publicclass PolyFit{
publicnativedouble[] polyFit(int[]iParams,double[] dParams,
double[] xx,double[] yy,int col);
static{
try{
System.loadLibrary("polylib");
}catch (UnsatisfiedLinkError e){
System.out.println ("Failed to load polylib");
e.printStackTrace();
}
}
public PolyFit(){
}
}
The parent java class is a sub class of Thread that calls the PolyFit when running as a thread:
....
int col2 = 2;
for(){//more than 1000 pairs of inputX and inputY
//iParams, dParams, inputX, inputY are assigned before
PolyFit polyFit =new PolyFit();
double[]output = polyFit .polyFit(iParams, dParams, inputX, inputY, col2);
....
}
Here is native C function (partial)
...
#include"PolyFit.h"
...
JNIEXPORT jdoubleArray JNICALL Java_org_ciit_stat_PolyFit_polyFit
(JNIEnv *env, jobject obj, jintArray ja, jdoubleArray jda,
jdoubleArray jdinX, jdoubleArray jdinY, jint col){
jdouble *output;
...
jdoubleArray dbArray = (*env)->NewDoubleArray(env, MAX);
(*env)->SetDoubleArrayRegion(env, dbArray, MIN, MAX, output);
free(output);
return dbArray;
}
Every call of polyFit .polyFit() may take less than 1 millisecond to several second. In case the time exceeds a threadhold, i.e. 10 second, we want to stop the thread. However, I can't find the way to stop or exit the C function.
Any ideas are highly appreciated.

