[英]How to manage multithread in java?
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 :
3rd function(cleaning up the system) will call only by the last thread. 第三函数(清理系统)将仅由最后一个线程调用。 Native functions
本机功能
setup(); 设定();
calculation(); 计算();
Cleanup(); 清理();
JNI functions JNI功能
JNIEXPORT jvoid JNICALL Java_taxcalc_setup JNIEXPORT jvoid JNICALL Java_taxcalc_setup
JNIEXPORT jstring JNICALL Java_taxcalc_calculation JNIEXPORT jstring JNICALL Java_taxcalc_calculation
JNIEXPORT jvoid JNICALL Java_taxcalc_cleanup JNIEXPORT jvoid JNICALL Java_taxcalc_cleanup
Java Code Java代码
public class taxcalc{ 公开课计税{
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(); }
public static String taxoutput(String[] args){ 公共静态字符串taxoutput(String [] args){
String array=""; 字符串array =“”;
for(int j=0;j<=5;j++) for(int j = 0; j <= 5; j ++)
{ {
input[j]=args[j];
} }
double y; y
int BilledLines; int BilledLines;
y=Double.parseDouble(args[6]); y = Double.parseDouble(args [6]);
BilledLines=Integer.parseInt(args[7]); BilledLines = Integer.parseInt(args [7]);
array=taxcalc.calculation(input,y,BilledLines,); array = taxcalc.calculation(input,y,BilledLines,);
return array; 返回数组;
} }
public static void main(String[] args){ 公共静态void main(String [] args){
System.out.println(taxoutput(args)); }
} }
taxouput function is multithreaded from osb.now,i want to call setup() and taxouput函数是来自osb.now的多线程,我想调用setup()并
cleanup() in way that it,setup() should called only for first thread and cleanup()只能通过第一个线程调用setup()
cleanup() should call only for last thread. cleanup()应该只调用最后一个线程。
From the code it seems you need to initialize and clean up using native functions. 从代码看来,您似乎需要使用本机函数进行初始化和清理。 This can be done using java multithreading but I would first look out for call back events in OSB from which you can invoke setup() and cleanup() methods .
这可以使用Java多线程来完成,但是我首先要在OSB中查找回调事件,您可以从中调用setup()和cleanup()方法。 This way it would be more cleaner.
这样,它会更清洁。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.