【发布时间】:2016-03-11 21:55:49
【问题描述】:
I have a Java function that is multi-threaded by OSB (oracle service BUs). This Java function calling three different native function through JNI. How to call these three function in such a way that :
- 第一个函数(设置系统)将只调用第一个线程。
- 第二个函数将被所有线程调用。
-
第三个函数(清理系统)将仅由最后一个线程调用。 原生函数
设置();
计算();
清理();
JNI 函数
JNIEXPORT jvoid JNICALL Java_taxcalc_setup
JNIEXPORT jstring JNICALL Java_taxcalc_calculation
JNIEXPORT jvoid JNICALL Java_taxcalc_cleanup
Java 代码
公共课税计算{
private static native void setup(); private static native String calculation(String input[],double y,int); private static native void cleanup(); static{ System.loadLibrary("CJavaInterface_64"); taxcalc.setup(); taxcalc.cleanup(); }公共静态字符串 taxoutput(String[] args){
字符串数组="";
for(int j=0;j
{
input[j]=args[j];}
双倍;
int BilledLines;
y=Double.parseDouble(args[6]);
BilledLines=Integer.parseInt(args[7]);
array=taxcalc.calculation(input,y,BilledLines,);
返回数组;
}
public static void main(String[] args){
System.out.println(taxoutput(args)); }}
taxouput 函数是来自 osb.now 的多线程,我想调用 setup() 和
cleanup() 的方式是,setup() 应该只为第一个线程调用,并且
cleanup() 应该只为最后一个线程调用。
【问题讨论】:
-
如果您需要详细的答案,请添加一些详细信息。从表面上看,这是信号量可以处理的事情,但我们需要了解更多。
-
您能否发布一些代码、您尝试过的内容以及您期望它的行为方式,以便我们更好地理解。
-
如果你有一些函数
f(...),并且你只想让某个线程调用它,那么你应该只在那个线程的代码中调用f(...)。 -
我添加了更多信息。
标签: java multithreading java-native-interface osb