Preserving session with JNI

I'm working on an application for interacting with a database, the database has a Java API and a C API for some of the backend functions. I'd like to use some of the C API for the backend to improve the performance of the application. The problem is that I can't pass the connection information back and forth between the Java side and the C side. The connection sessions are maintained by objects in either API (a Java class for connections and a C class for connections). These classes aren't identical, but they're very similar.
I'm not very experienced with JNI, but as far as I've read/tried, I can't pass these objects back and forth between Java and C. Since JVM addressing isn't necessarily absolute, I can't rely on getting an address to reference on the C side, and since (as far as I'm aware) I can only instantiate a Java side connection with Java side methods, I can't refer to a connection from the C-side either.
Long story short, I'm stuck trying to find a way to make these 2 API's get along so that I can get the added performance of the C backend. For some reason the API's don't have any methods that use session ID's or anything else that would be useful for this sort of thing. Maybe there is something else I could try or maybe I'm just missing something (it wouldn't be the first time).
Any thoughts/ideas/suggestions would be much appreciated.

nsop07 wrote:
I'm working on an application for interacting with a database, the database has a Java API and a C API for some of the backend functions. I'd like to use some of the C API for the backend to improve the performance of the application. And why do you think that will work?
The problem is that I can't pass the connection information back and forth between the Java side and the C side. The connection sessions are maintained by objects in either API (a Java class for connections and a C class for connections). These classes aren't identical, but they're very similar.
I'm not very experienced with JNI, but as far as I've read/tried, I can't pass these objects back and forth between Java and C. Since JVM addressing isn't necessarily absolute, I can't rely on getting an address to reference on the C side, and since (as far as I'm aware) I can only instantiate a Java side connection with Java side methods, I can't refer to a connection from the C-side either.
In java you perserve a pointer, any pointer, via a java long value. Cast it back and forth when you go back and forth.
Don't forget to provide a mechanism to clean it up.
Java objects are similar and well defined in JNI - you pass a reference and access it via JNI methods.

Similar Messages

  • Problem with JNI and Parallel Port dll

    Hi. I'm doing some testes with JNI. Firs i followed the netbeans tutorial for doing a C programa that prints somthing for java.. like.. "Hello java from C".
    So i tried to load a dll from my dll. Like, I have this dll to use the parallel port on windows Xp. So i created a dll to access it an comunicates eoth java.
    I did everything just fine.
    When I start my Java app, the first thing it does is to load this parallel port dll and configure the functions of it.
    After that .. I get this error
    EXCEPTION_FLT_STACK_CHECK (0xc0000092) at pc=0x0093d269, pid=2284, tid=3000
    Can someone explain why ?
    (Sorry if i wasn't clear enough, english is not my native language, so ask if you don't understand something.. )

    hi ,
    I met the same problem this morning, and searched the www.google.com in order to solve it, as a result, your article was shown on my screen. :)
    Till now I have read some technical information and solved my problems. Maybe the solution be useful to you:
    ==============================
    error message : (Environment : Tomcat 5, Windows 2003, Mysql5)
    2006-3-29 11:53:48 org.apache.catalina.core.StandardWrapper unload
    message: Waiting for 2 instance(s) to be deallocated
    ==============================
    cause: the number of connection to database exceeded.another word,too many connections.
    ==============================
    solution: close the connection when it becomes useless for your program. :)
    ==============================
    ps. Sorry for my weak English . hehe ....

  • Problem with JNI

    i have to implement a few standard APIs. As a part of the implementation I have to provide references to an object I create. Now my underlying code is C++ with JNI used to throw the Java APIs. Problem is JNI now returns different references for the same object and hence my prupose id defeated. Could anyone suggest how this problem can be overcome.

    I tried to figure out what your problem is, but can't. Please rephrase it and give a bit more detail on what you are doing and what is going wrong.

  • Problem with jni references

    i have to implement a few standard APIs. As a part of the implementation I have to provide references to an object I create. Now my underlying code is C++ with JNI used to throw the Java APIs. Problem is JNI now returns different references for the same object and hence my prupose id defeated. Could anyone suggest how this problem can be overcome.

    I'm not exactly sure what you're talking about, but it sounds like you may need to look into global references. Look at NewGlobalRef() and DeleteGlobalRef() and see if those help you out.
    God bless,
    -Toby Reyelts
    For all your JNI woes, check out Jace - http://jace.reyelts.com/jace

  • Problem with JNI form C++

    Hi all,
    I'm fairly new to programming with JNI, so please excuse me if I ask a dumb question.
    I'm trying to call a Java method from a C++ class, but when I run the program, it throws an error, crashing the program. I'm pretty sure the problem is that the call to env->getMethodID() is throwing an error. I have looked around to try and find a way call a function with no arguments, but all of the examples that I have found all call a Java main.
    I'll post my code and the error message below so that things are a bit clearer.
    Thanks,
    Robert.
    Here is the main.cpp. This is where the program is started.
    #include "/usr/lib/jvm/java-6-sun-1.6.0.06/include/jni.h"
    int main()
       JNIEnv *env;
       JavaVM *jvm;
       jint res;
       jclass cls;
       jmethodID mid;
       // creation of the JVM
       JavaVMInitArgs vm_args;
       JavaVMOption options[1];
       options[0].optionString = "-Djava.class.path= .";
       vm_args.version = 0x00010002;
       vm_args.options = options;
       vm_args.nOptions = 1;
       vm_args.ignoreUnrecognized = JNI_TRUE;
       res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
       // now the rest of the code can work
       cls = env->FindClass("Test");
       mid = env->GetMethodID(cls, "run", "()V");
       env->CallVoidMethod(cls, mid);
       jvm->DestroyJavaVM();
    }Here is Test.java
    public class Test
       public void run()
          System.out.println("stuff");
          foo();
       public void foo()
          System.out.println("asdfasdf");
    }And here is the error message.
    # An unexpected error has been detected by Java Runtime Environment:
    #  SIGSEGV (0xb) at pc=0x06245f7d, pid=9054, tid=1076641792
    # Java VM: Java HotSpot(TM) Client VM (10.0-b22 mixed mode, sharing linux-x86)
    # Problematic frame:
    # V  [libjvm.so+0x245f7d]
    # An error report file with more information is saved as:
    # /media/MY STICK/jni/cpp/hs_err_pid9054.log
    # If you would like to submit a bug report, please visit:
    #   http://java.sun.com/webapps/bugreport/crash.jsp
    AbortedEdited by: metaldrummer610 on Apr 23, 2008 8:35 PM

    Yeah, so I just figured out what was wrong. I wasn't calling main from in Java. My bad guys.

  • Call transaction in new session with the value at hotspot

    Hi all,
    As a hotspot functionality I would like to open a new transaction in a new session with the value at hotspot. For that reason, I am using the FM ABAP4_CALL_TRANSACTION with the option STARTING NEW TASK.
    This FM is not working because Parameter ID is not Maintained for the field (Hotspoted). So no value is passing to new transaction.
    Please suggest any other way to implement this.
    Thanks

    Hi Anil..
    This is the Solution for ur Requirement.   try this program and change as per ur need.
    REPORT  ZSEL_CALL_TCODE.
    data : IT_KNA1 TYPE TABLE OF KNA1 WITH HEADER LINE.
    DATA : IT_SPA TYPE TABLE OF RFC_SPAGPA WITH HEADER LINE.
    SELECT * FROM KNA1 INTO TABLE IT_KNA1 .
    LOOP AT IT_KNA1 .
      WRITE:/ IT_KNA1-KUNNR HOTSPOT ON.
      HIDE IT_KNA1-KUNNR .
    ENDLOOP.
    CLEAR IT_KNA1-KUNNR.
    AT LINE-SELECTION.
    CASE SY-LSIND.
    WHEN 1.
    IF IT_KNA1-KUNNR IS NOT INITIAL.
    REFRESH IT_SPA.
    IT_SPA-PARID = 'KUN'.
    IT_SPA-PARVAL = IT_KNA1-KUNNR.
    APPEND IT_SPA.
      CALL FUNCTION 'ABAP4_CALL_TRANSACTION' STARTING NEW TASK 'S1'
        EXPORTING
          TCODE                         = 'XD02'
         SKIP_SCREEN                   = ' '
        MODE_VAL                      = 'A'
        UPDATE_VAL                    = 'A'
      IMPORTING
        SUBRC                         =
       TABLES
        USING_TAB                     =
         SPAGPA_TAB                    = IT_SPA
        MESS_TAB                      =
      EXCEPTIONS
        CALL_TRANSACTION_DENIED       = 1
        TCODE_INVALID                 = 2
        OTHERS                        = 3
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      ENDIF.
    ENDCASE.
    <b>Reward if Helpful.</b>

  • You cannot shadow a session with multiple monitors enabled in Windows Server 2008 R2

    Searching through the forums (and according to KB2484290) it appears that there is no solution to this problem.  We are rolling out thin clients that are using dual monitors exclusively and we were very surprised to find out that we couldn't shadow
    sessions with dual monitors (which to us means that we can't shadow ANY sessions).  This now completely changes our approach to managing these devices. 
    We are running Windows Server 2008 R2 SP1 with Remote Desktop Services installed.  The thin clients are running Windows Embedded Standard 7 with the latest updates / RDP client. All steps have been followed to ensure that the apropriate settings and
    permissions have been set up to allow access into the session. 
    We tested by unchecking the RDP setting “use all my monitors for the remote session”, with that setting disabled shadowing worked
    Questions:
    1. KB2484290 is from Dec 2010 - It's now April 2012, is there a workaround / hotfix for this issue that will allow us to shadow sessions using the native Microsoft tools?
    2. Are there any recommended alternatives (software)?  Free/Paid - doesn't matter we just need something that will work.  I'm sure there are a few options out there but I am looking for suggestions for what people have used in the past that worked
    best for them to help us narrow down the choices.

    Hi,
    In my experience, so far, the workaround is Remote Assistance, Remote Assistance supports multiple monitors, and is the presently recommended solution if you need this functionality. Remote Assistance is a Windows Server Feature that must be explicitly installed
    on Windows Server 2008 R2; it is already installed with the client versions of the operating system.
    More information:
    Remote Assistance Overview
    http://technet.microsoft.com/en-us/library/cc753881.aspx
    Remote Assistance and Resulting Internet Communication in Windows Server 2008
    http://technet.microsoft.com/en-us/library/cc770456(v=ws.10).aspx
    As far as I know, there are some third-party tools can be used as the solution, such as Teamviewer, ISL Online, etc.
    Please Note: The third-party products discussed here are manufactured by companies that are independent of Microsoft. We make no warranty, implied or otherwise, regarding
    these products' performance or reliability.
    Regards,
    Dollar Wang
    Forum Support
    TechNet Subscriber Support
    If you are TechNet Subscription user and have any feedback on our support quality, please send your feedback
    here.
    Technology changes life……

  • How do I create a session with the datasource set in code not sessions.xml

    I want to create a session where I specify the J2EE datasource name dynamically in code. Normally, I would hard-code a J2EE datasource name in sessions.xml e.g.
    <login>
    <datasource>jdbc/MyApplicationDS</datasource>
    <platform-class>oracle.toplink.platform.database.oracle.Oracle10Platform</platform-class>
    <uses-external-connection-pool>true</uses-external-connection-pool>
    <uses-external-transaction-controller>true</uses-external-transaction-controller>
    </login>
    However, we don't want to use a hard-coded string "jdbc/MyApplicationDS". We want to be able to set this at runtime.
    I found this in the App Developer's Guide:
    Configuring an External Connection Pool in Java
    To configure the use of an external connection pool in Java:
    1. Configure the DataSource on the server.
    2. Configure the Login to specify a DataSource and the use of an external connection pool:
    login.setConnector(
    new JNDIConnector(new InitialContext(), "jdbc/MyApplicationDS"));
    login.setUsesExternalConnectionPooling(true);
    and this:
    Configuring Sessions with the sessions.xml File
    OracleAS TopLink provides two ways to preconfigure your sessions: you can export and compile Java source code from the OracleAS TopLink Mapping Workbench, or use the OracleAS TopLink Sessions Editor to build a session configuration file, the sessions.xml file.
    It seems like I should export and compile Java code that calls login.setConnector(), but I can't find out any information on how to do this. I looked at the MW user guide and I didn't see anything on this.
    I also found this by searching this discussion forum:
    To create a server session completely from code given a project you can use,
    project.getLogin().setConnector(new JNDIConnector(new InitialContext(), "your-datasource-url"));
    project.getLogin().setUserName("");
    project.getLogin().setPassword("");
    Server server = project.createServerSession();
    server.login();
    However, I don't know how to get the project.
    Thanks,
    Vicki

    If you are using a sessions.xml file, you can get your project from your session. Ensure that when you access your session from the SessionManager, that you do not have it login.
    Session session = SessionManager.getManager().getSession("my-session", false);
    session.getProject().setConnector(...);
    session.login();
    If not using a sessions.xml, you can either read your Project from the XMLProjectReader, or instantiate your Project class directly.

  • Opening a new JFrame in a specific DISPLAY on X11 environment with JNI

    Hi,
    I have a problem that I'm unable to solve.
    I have a Java Application (on Linux with X11 XServer display manager ) running in background that has to open, once received the request, JFrames on the client display. So if I launch the client from "display1", I have to open a JFrame on display1 and then if I launch again the client from "display2", I have to open a JFrame on display2.
    But I found no way do specify where (on which display) I want to open my frame.
    I saw there is a JFrame constructor using GraphicsConfiguration but it I can access only to Local GraphicsConfiguration, so I didn't understand the meaning of this parameter. ;-)
    I tryed even to change runtime the value of $DISPLAY environment variable just before the "new" call but it seems that awt connect to XServer only the first time I use a "graphic call" using correctly my $DISPLAY changed value.
    So all my frames appear on the display from which the first client connects.
    There is a way to tell awt to open a window on a specific DISPLAY without JNI ?
    Or, with JNI it's possible to override, in the X11DrawingSurfaceInfo structure, the field "display" (opening a new connection when necessary) for specific JFrame and the return the changed value to the AWT engine ?
    Thanks to all

    Hi,
    Have you had any further luck with this? I'd like to do something very similar to this (read from a config file the XServer address and use it at runtime to display on that particular server - I have multiple displays with different addresses).
    The best I can figure so far is to use ProcessBuilder and launch another java process with the $DISPLAY env variable set (differently for each process - or client display in your case).
    Whilst I may be able to get away with this for my project, it has many many disadvantages and I'd like to be able to change this programmatically/on-the-fly.
    Anyone's help would be greatly appreciated.
    I may just have to scrap using Java..

  • LIBOVD ERROR  - "validateContextToken: workflow session was not found for given context. Create a new workflow session with token"

    Hello everyone,
    I have the following scenario:
    We're using "Oracle SOA Suite 11g 11.1.1.7.0" (Patched w/ 17893896) mainly for a BPM/Human workflow composite. Former, we were having the error bellow:
    <Mar 16, 2015 1:13:03 PM BRT> <Error> <oracle.soa.services.workflow.query> <BEA-000000> <<.> Verification Service cannot resolve user identity. User weblogic cannot be found in the identity repository. Workflow Context token cannot be null in request.
    ORABPEL-30511
    When that error ocurred, no one was able to use the system (BPM/Human Workflow).
    I opened an SR, and after some analysis from the support, it recommended me to set up "virtualize=true" in EM, and restarting the domain. Then it started logging the following:
    connection to ldap://[10.200.10.57]:7001 as cn=Admin.
    javax.naming.NamingException: No LDAP connection available to process request for DN: cn=Admin.
    Looking up on support KB, I found this note Doc ID 1545680.1 and increased from Max size of Connection Pool 10 to 200. That did work successfully! Problem now is that the <SERVER>_diagnostic.log is being filled up with the following error:
    [2015-03-31T16:03:46.421-03:00] [soa_server2] [ERROR] [] [oracle.soa.services.workflow.verification] [tid: [ACTIVE].ExecuteThread: '19' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: <anonymous>] [ecid: e0194e38aa6c9a2f:39fc1ff9:14c5def5247:-8000-00000000000a5653,0] [APP: soa-infra] <.>    validateContextToken: workflow session was not found for given context. Create a new workflow session with token=51490173-e3d0-41dd-ae99-983915aa8454;;G;;Z+P7Oe9ABnoTUQD9ECryEW2l0/8yRcqPDyZsOWBCuzMmRgA3Qsj601TxmWQ87z2MjuwW5AH+KzgjIwkPmhJFdpc1FrE6Y/MrN1bxIDHJWu2/zP3iSNwKD07hRrh/U37Ea0TvaQyuaHJIog9y3Ptmzw==
    One important point is that we're using only the embedded WLS ldap. So I am not 100% sure if we should be using the virtualize flag=true, once all docs I read point out that this should be done when using multi-ldap providers.
    Also, I only got this error in the "diagnostic.log".
    Although, no user has complained about using the system, I really want to work it out. Anyone has any suggestions?
    Thanks in advance!

    I have moved your thread from Certification to SOA Suite to get proper assistance.
    Thanks,
    Lisa

  • HT200169 Having a problem with Logic 9 on a Mac Pro.Working on a lenghty song and apparently session got corrupted.Doesnt let me export tracks,program crashes.Already tried start brand new session with the tracks imported into it but still wont export.Sug

    Hello,having a problem with Logic 9 on a Mac Pro.Working on a lenghty song and apparently session got corrupted.Doesnt let me export tracks,program crashes.Already tried start brand new session with the tracks imported into it but still wont export.Suggestions?

    Thanks, Ian. Yeah, that's how I do it now...or with the controls in the left side pane. Still, I would have liked that quick on-the-spot edit capability...especially while sketching.
    Ian Turner wrote:
    Sorry Mark, you are out of luck as it does not do that - it works the same as L8. The way I would achieve that with more accuracy and control would be to route all the tracks you want to fade to a Bus then use volume automation on the bus. To do this you will need to add a standard audio track, then re-assign it using (Control Click on the track header) to the Bus track. You can then automate volume/plugins etc on the Bus track.
    Ian

  • Unable to establish a session with the Address Book Server

    I have installed the following
    Sun Java System Messaging Server 7 Update 3
    Sun Java System Calendar Server 6.3
    Sun Java System Directory Server 6.3.1
    GlassFish Enterprise Server 2.1 Patch 2 with HADB support
    Delegated Administrator 7
    Sun Convergence 1 Update 3
    as per the instruction here
    http://wikis.sun.com/display/CommSuite7/Sun+Java+Communications+Suite+7+on+a+Single+Host
    My problem is that when I open outlook and try to add a new contact, I get a message saying:
    Unable to establish a session with the Address Book Server. Contact your server administrator for help or try later.
    When using webmail, I can add contacts just fine.
    How can I fix this problem?
    Thanks
    Edited by: Nevron on 26 ??? 2010 11:31 ??

    Nevron wrote:
    My problem is that when I open outlook and try to add a new contact, I get a message saying:
    Unable to establish a session with the Address Book Server. Contact your server administrator for help or try later.Refer here:
    http://forums.sun.com/thread.jspa?threadID=5424727
    You need to log a Sun support request to get the latest Convergence patch.
    Regards,
    Shane.

  • TS3103 All of a sudden can't receive email on Mail client.  Sessions with service provider (Att/yahoo) and Apple have yielded no results!

    All of a sudden can't receive email on Mail client.  Sessions with service provider (att/yahoo) and Apple have yielded no results!  Recently upgraded to Lion, but have received email since.  Anyone having the same problem.  Apple says service provider problem, service provider say it's the mail client.  Anyone had this problem???

    No.  My frustration with the problem just led me to begin the process convert all my email to a gmail client.  However, after some time all my mail with att/yahoo has been coming through as before.  Go figure.  Still will convert to gmail.

  • Kill inactive sessions with no programs run it

    hi all,
    my database is 10gR2 with developer 6i
    the database have huge number of sessions with no programs running it like oracle form, some of those sessions stack in v$session table due to power failure.
    restart server solve the problem, but it is not efficient.
    is there any method to fined witch of database sessions is actually connect to the database and have application running it ?

    This script will give you the complete detail of Session , PID and Program which is running in dagtabase level.
    You can include the "STATUS" coloumn from v$session to get user status.
    Script is like this:
    set echo off;
    set termout on;
    set linesize 80;
    set pagesize 60;
    set newpage 0;
    select
    rpad(c.name||':',11)||rpad(' current logons='||
    (to_number(b.sessions_current)),20)||'cumulative logons='||
    rpad(substr(a.value,1,10),10)||'highwater mark='||
    b.sessions_highwater Information
    from
    v$sysstat a,
    v$license b,
    v$database c
    where
    a.name = 'logons cumulative'
    ttitle "dbname Database|UNIX/Oracle Sessions";
    set heading off;
    select 'Sessions on database '||substr(name,1,8) from v$database;
    set heading on;
    select
    substr(a.spid,1,9) pid,
    substr(b.sid,1,5) sid,
    substr(b.serial#,1,5) ser#,
    substr(b.machine,1,6) box,
    substr(b.username,1,10) username,
    -- b.server,
    substr(b.osuser,1,8) os_user,
    substr(b.program,1,30) program
    from v$session b, v$process a
    where
    b.paddr = a.addr
    and type='USER'
    order by spid;
    ttitle off;
    spool off;
    Save this script with your desire name and run in Database.
    Mukesh

  • Old Oracle Session with Tomcat is not kiiling automatically

    Hi,
    I am facing a problem of increasing inactive oracle sessions with tomcat, Old Oracle sessions with tomcat are visible with new one.
    if somebaody did not restarted tomcat gracefully, then does Oracle keep the session connected or is there any way that whenever any one restarted tomcat abnormally, Oracle session can be killed.
    I had restart the database to kill session.

    Could you please tell me that where do i set this parameter in parameter file or sql net file and what is the recommended value, do you have any document on this.
    Another thing tomcat is in other server machine and my database is in different server machine, killing process in tomcat server machine manually may not kill linux process on oracle database machine and therefore oracle sessions are still there.
    Is it possible?
    Edited by: user605066 on 28-Aug-2008 04:59

Maybe you are looking for

  • Class with objects compile error in Java 1.5.0 and 1.4.2.05

    Hi, I have some problems with creating objects to my java program. See below: JAVA, creating new class object. class AccountTest {      public static void main(String[]args) {      Account olesAccount = new Account(123456676756L, "Ole Olsen", 2300.50

  • Urgent! Node keep disconnecting from Coherence Cluster

    The system consists of 4 standalone cache servers with local storage set to true and 14 other embedded nodes started with different web apps on tomcat with local storage set to false. When the servers are started after a new deployment, sometimes it

  • Can I make two differents selection screen in my program?

    Hi experts!! I don't know how to male this, the problem is that I need to make two differents selection screen in my program because I have two differents kinds of button, BUTTON1         BUTTON2          BUTTON3 When I press button1 I received. BUTT

  • REPLACEMENT WIFI ANTENNA FOR F4580 DESKJET ALL IN ONE PRINTER

    HI I WONDER IF ANY OF YOU GUYS AT HP CAN TELL ME WHERE I CAN GET HOLD OF A REPLACEMENT WIFI LEAD/ ADAPTER/ ANTENNA TYPE LEAD THAT PLUGS INTO THE BACK OF MY DESKJET F4580 ALL IN ONE PRINTER , ITS SORT OF 8mm SQUARE IN SHAPE THANK YOU FOR YOUR TIME

  • HP color laserjet 4600 parallel port is wierd need help to identify

    Hi I have a laserjet 4600 and it has a wierd looking parallel port and I can't seem to find out the name for it so I can buy it online. I have tried looking for it online but the only thing that comes up is the IEEE 1284 36 pin parallel port. Can any