JNI:Performance:Suggestions/Advice needed

Discussion in 'Java' started by Ganesh, Apr 3, 2004.

  1. Ganesh

    Ganesh Guest

    I have an issue which I am unable to decide on regarding JNI. Would be
    glad if someone could help me out.
    This is the requirement:

    I need to pass around 20 values, all belonging to different logical
    sets (for eg., 4 are related to employee details, 3 are related to
    salary details etc). which finally belong to a larger logical
    unit(company information) from the Java side to the C++ side for

    I have 2 ways to do this
    1. Make objects of all relevant information in the Java side, a Salary
    class which will contain all salary details, an Employee class with
    all employee information, and store all these in a single object
    called CompanyInfo (say). I pass this object to the C++ side, which
    a. uses the main object and get all the objects inside such as
    salary, employee etc.
    b. Calls the get methods of salary object, employee object etc. to
    retrieve all the values required for processing.
    C. Does processing using the required values.

    2. Store _all_ the values required for the operation in a single
    array/arraylist in Java and pass it to the C++ side. C++ side
    retrieves it in a pre-determined order, gets the values and does the

    Now, I am inclined towards 1 since the code will be well-organized,
    objectified and easy to maintain. The whole design follows a logical,
    constructive pattern. Whereas 2 looks crude, with everything dumped
    into one array with no logical separation and bad code which is ough
    to understand and maintain.

    My problem is that I am worried about the effect on performance if I
    choose 1. If 20 values are to be retrieved, then 20 callback
    operations (from C++ to JNI) have to be done to call the get methods
    and the values have to be got. How costly would this turn out to be?
    Will option 2 be drastically cheaper in terms of time taken? The Java
    site says C++ to java/java to C++ call takes atleast 2-3 times the
    time taken by a Java-Java call. :-(

    My test programs don't reveal much as there is hardly any load. This
    logic will go into a web-app which will be used by thousands of users
    concurrently, so could anybody please advise on which would the better
    option from a performance viewpoint?

    Or is there a different solution to this requirement?

    maybe something midway like each java object having a single get
    method which would return an array of all the values in it. i am just

    I would appreciate any advise you could give me.

    Thanks and Regards
    Ganesh, Apr 3, 2004
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley

    IBM's JNI fails where Sun's JNI works

    Alex Hunsley, Nov 3, 2003, in forum: Java
    Alex Hunsley
    Nov 4, 2003
  2. Pasturel Jean-Louis

    Porting JNI Windows under JNI LINUX + Wine ?

    Pasturel Jean-Louis, Feb 29, 2004, in forum: Java
    Pasturel Jean-Louis
    Mar 3, 2004
  3. Ganesh
    Chris Uppal
    Apr 3, 2004
  4. vasanth
    Jan 25, 2005
  5. vasanth
    Jan 25, 2005

Share This Page