0
votes
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 :
  1. first function (setting up the system) will call only for 1st thread.
  2. 2nd function will call by all thread.
  3. 3rd function(cleaning up the system) will call only by the last thread. Native functions

    setup();

    calculation();

    Cleanup();

    JNI functions

    JNIEXPORT jvoid JNICALL Java_taxcalc_setup

    JNIEXPORT jstring JNICALL Java_taxcalc_calculation

    JNIEXPORT jvoid JNICALL Java_taxcalc_cleanup

    Java Code

    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){

    String array="";

    for(int j=0;j<=5;j++)

    {

    input[j]=args[j];
    

    }

    double y;

    int BilledLines;

    y=Double.parseDouble(args[6]);

    BilledLines=Integer.parseInt(args[7]);

    array=taxcalc.calculation(input,y,BilledLines,);

    return array;

    }

    public static void main(String[] args){

            System.out.println(taxoutput(args));
    
    }
    

    }

    taxouput function is multithreaded from osb.now,i want to call setup() and
    cleanup() in way that it,setup() should called only for first thread and
    cleanup() should call only for last thread.

1
Please add some detail if you want a detailed answer. On the face of it, it's something semaphores can deal with but we need to know more.biziclop
can you post some code, what you've tried and how you're expecting it to behave, so that we may get a better understanding.Akash Raghav
If you have some function, f(...), and you only want a certain thread to call it, then you should only put calls to f(...) in the code for that thread.Solomon Slow
I have added some more information.chandra Deep

1 Answers

0
votes

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 . This way it would be more cleaner.