After AttachCurrentThread: Calling back to Java method crashes JVM

Hi,
so I managed to get my multithreaded native code being invoked from a Java program.
However, as soon as I try to invoke a Java callback from native code not running in the main thread, the program segfaults. Here's my code:
// in the main thread, I store a pointer to the JVM that invokes this code
    if (env->GetJavaVM(&jvm) < 0) {
        std::cerr << "JNI ERROR: Failed getting reference to Java VM" << std::endl;
        return;
    assert (jvm != NULL);
// in some other concurrently running (native) thread:
    JNIEnv *env;
    if (jvm->AttachCurrentThread((void**)&env, NULL) != JNI_OK) {
        std::cerr << "ERROR: Could not attach event thread to JVM" << std::endl;
        return;
    assert (env != NULL);
    assert (connector != NULL);
    assert (focusEventCallback != NULL);
    // the following line segfaults
    env->CallVoidMethod(connector, focusEventCallback);"connector" is a POJO, focusEventCallback the jmethodID referencing the Java callback.
Am I missing something?
Thanks in advance,
Matthias

jschell wrote:
What do you mean by that? I get this reference in the main thread in JNI_OnLoad and I use it in another thread. So I use it across thread boundaries. Is that what you mean?Generally not a good idea.So what do you suggest?
Getting that reference inside the thread where I use it didn't work, because the class lookup failed (ClassNotFoundException).Which means your code was wrong, not that it wouldn't work.So, what in particular was wrong about my code? Here is the section of the code that did not work, because the class lookup failed:
    JNIEnv *env = NULL;
    // "import" the native user level thread as a Java thread in the JVM
    if (jvm->AttachCurrentThread((void**)&env, NULL) != JNI_OK) {
        std::cerr << "JNI ERROR: Could not attach X11 event thread to JVM" << std::endl;
        return;
    jclass connectorClass = env->FindClass("de/dfki/km/mydesk/nativeInterfaces/linux/NetWmConnector");
    if (env->ExceptionOccurred()) {
        env->ExceptionDescribe(); // will output ClassNotFoundException
    }The same code works inside JNI_OnLoad.
Well, an assertion is supposed to do that: Terminate the program if there is a condition that would stop the program from operating properly. The crashes I was talking about are segmentation faults. A failing assertion is not a crash, it will just terminate the program with an "assertion failed" message.You are not writing a C/C++ app. You are running some code in a shared library that is run from a VM.
Very different.
I haven't tried it but I am rather certain that if you cause an assertion failure that you are going to see a crash. So far as I know the only exit mechanism that doesn't cause the VM to crash explicitly is a system exit call. And that probably shouldn't be used either (not normally.)Well, as far as I know, assert() sends an abort signal and terminates the process (which is the VM in this case). I probably overused assertions in that I used them to probe for runtime errors, not for programming errors. I'll remove them from the retail code anyway, so for now, it's just fine that the program terminates if something goes wrong. It helps locating the offending LOC.

Similar Messages

  • Is is possible to call a function or method before JVM exits ??

    Hi All,
    Is is possible to call a function or method before JVM exits where System.exit() is used.
    I am calling a program where System.exit is used. i need to call a function before the JVM exits.
    Please help me.
    Thanks,
    J.Kathir

    How to call the method ? Did i have to call the shudown hooks method in my main class ?
    Is it possible to have in subclass?
    is the below code is correct ? i am calling a class before System.exit is called....
    java.lang.Runtime.getRuntime().addShutdownHook(...My Own Class()....)

  • Problem with OSB 11g - Unable to call non-static java methods

    I have a problem in OSB. Unable to see any java methods when loading java callout. I have checked the java classes in the .jar file and they are all non-static java methods.
    Is there any way where OSB is able to see this non-static java methods?
    Need help urgently!
    Thanks!

    Technical standpoint: Do you know why OSB is not able to call non-static methods?
    This is by design. Ability to call non-static methods require Object creation which adds additional complexity. eg How to pass variables in constructor?. How/where to store created object for use across across pipeline instance?. Object life cycle (when and how to create object) etc. To avoid above complexites static methods are only supported.
    "a lot of non-static method to call" just for my understanding what are the number involved?. If number is too high you can always request for a enhancement.
    Thanks
    Manoj

  • Calling a external Java method from JSP - using Tomcat server

    Hi all,
    I am trying to call a method in an external Java file from my JSP. I am using Tomcat server.
    I have my class within the package package "mypackage" and it is called myclass.class. It has only one static method mymethod() which reads from a file and writes to a file.
    I compiled the java class and I put the class file under webapps/ROOT/web-inf/classes/mypackage/myclass.class
    I am trying to say something like this from my JSP file(which is under webapps/ROOT) :
    <%@ page import = "mypackage.myclass"%>
    <% myclass.mymethod(); %>
    I am not instatiating the class as its a static method.
    This is what I get while accessing my jsp file :
    javax.servlet.ServletException: try to access class mypackage.myclass from class org.apache.jsp.index_005ftest_jsp
    To put my problem in a nutshell, Can someone guide me how to access a method of an external class from a JSP page? I have a bunch of pages doing the same operation so I thought I would have it in a method and call it from every page. Even though I tried to put the file under web-inf/classes, The JSP is not able to see the class.
    Please help.
    Thanks
    -Uday

    I have a situation that is a bit similar. I have successfully used beans for storing methods used in JSPs and used by other methods in the same class as was suggested above. Now I would like to break some methods into another (utility) class since they are lower level and can be used by lots of things. They are for database operations (given a String query and String dbname, it queries and returns ResultSet for example). I want to have them in a separate class for reusability and OOP.
    I am having problems calling those public static methods in the public class from my bean that communicates with the JSP. I can't compile the class that calls the method in the database ops class. I get an error like :
    loginHelper.java:45: cannot find symbol
    symbol : variable sqlHelper
    location: class dbHelperBean.loginHelper
    and when I include the package name in the call I get
    loginHelper.java:45: cannot find symbol
    symbol : class sqlHelper
    location: package dbHelperBean
    That's strange since the package of both classes is dbHelperBean and the class is indeed called sqlHelper. I tried to compile it in the same directory as sqlHelper as well. What am I doing wrong?
    Thanks for any help.

  • How to call Back end Bean method on Refresh (F5 from i.e.)

    I am very much new to JSF. I tried hard learning it. But I am not able to achive one thing.
    Question :
    How do we set some value in Back end bean when user presses F5(refresh from i.e)
    I have some root tag as given below. I tried checking properties of a4j:form but nothing seems to be releveant.
    <ui:composition>
         <rich:panel>
              <a4j:form id="FirstForm">
    I am kind of stuck with one week. Please provide help.

    Pasting the entire sample code. Here bBean is singleton.
    <ui:composition>
         <rich:panel>
              <a4j:form id="FirstForm">
         <table id="table" width="100%">
                        <tr>
                             <td style="margin-top: 8px;" class="fieldLabel" nowrap="nowrap"
                                  align="left" width="15%">
                             <p><h:outputText value="Option Name :">
                             </h:outputText> <span class="requiredField">*</span></p>
                             </td>
                             <td style="margin-top: 8px; width: 120px" class="fieldLabel"
                                  nowrap="nowrap" align="left"><rich:comboBox id="combo"
                                  value="#{bBean.selectedOption}"
                                  enableManualInput="false">
                                  <f:selectItems value="#{bBean.getAllOptions}" />
                                  <a4j:support event="onchange"
                                       reRender="FirstForm" BypassUpdates="false"
                                       ajaxSingle="true"" />
                             </rich:comboBox></td>
                        </tr>
                   </table>
              </a4j:form>
         </rich:panel>
    </ui:composition>
    </html>

  • Anyone can prove JNI is safe? My application crashes after many calls.

    I heard that JNI is not safe. In fact I made an application base on many JNI calls.
    C level is API supplied by IBM. And I was told the C API is tested and safe.
    Java application and JNI calls is writen by myself. It crashed after about 3000 times call. I tried other JDK and other OS. On some platform, the thread hold there after many calls. No error, no crash. But others crashed even early.
    Here's my JNI call's code:
    JNIEXPORT void JNICALL Java_com_ibm_mm_sdk_cim_internal_PServiceFACImp_cEvaluate
    (JNIEnv *env, jclass jobj, jlong jhandle, jstring jmanualedListFilename, jstring jclassedListFileName, jstring jresultFilename){
         char *manualedListFilename = jstringToWindows(env, jmanualedListFilename);
         char *classedListFileName = jstringToWindows(env, jclassedListFileName);
         char *resultFilename = jstringToWindows(env, jresultFilename);
         int rc;                         // API return code
         void* handle;               // FAC Handle
         // convert C pointer from java long type
         handle = (void*)jhandle;
         rc = KmFAC_Evaluate(
              handle,                                   // FAC Handle
              (char*)manualedListFilename,     // File name of list of files
              (char*)classedListFileName,          // File name of list of files
              (char*)resultFilename               // Result file
         if (manualedListFilename)
              free(manualedListFilename);
         if (classedListFileName)
              free(classedListFileName);
         if (resultFilename)
              free(resultFilename);
         if (rc != KM_RC_OK) {
              //Throw exception
              jclass exceptClass;          // JNI exception class
              char errorMsg[256];          // Used to build error msg for exceptions
              jmethodID methodid;          // Exception constructor method id
              sprintf(errorMsg, "KmFAC_Evaluate() [CKM=%d]", (int)rc);
              exceptClass = env->FindClass("com/ibm/mm/sdk/cim/DKServiceExceptionCIM");
              methodid = env->GetMethodID(exceptClass,"<init>","(Ljava/lang/String;II)V");
              jstring str = env->NewStringUTF(errorMsg);
              jthrowable excobj = (jthrowable)env->NewObject(exceptClass,methodid,str,100, (int)rc);
              env->Throw(excobj);
         return;

    I agree with fury88. Try the code below it works fine!
    // **************** Java portion ************************
    public class Test {
    // Load the dll that exports functions callable from java
    static {System.loadLibrary("TestImp");}
    // Imported function declarations
    public native void print(String msg);
    public void Test() {
    public static void main(String [] args) {
    Test t = new Test();
    // Printf example
         t.print("->Testing JNI - Hello from c++\n");
    // **************** Windows portion - TestImp.dll **********************
    // Exported function
    JNIEXPORT void JNICALL Java_Test_print(JNIEnv *env, jobject obj, jstring msg)
    const char *str = env->GetStringUTFChars(msg, 0);
    printf("%s\n", str);
    env->ReleaseStringUTFChars(msg, str);
    // Entry point
    BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
         switch(ul_reason_for_call)
              case DLL_PROCESS_ATTACH:
                   return TRUE;
              case DLL_PROCESS_DETACH:
                   return TRUE;
    return TRUE;
    }

  • Call Java Method from Callback function

    I am writing a JNI wrapper in c++ for a particular event driven DLL. The DLL makes a network connection to another device and then calls a callback function when events are raised on the device. The DLL has 3 basic functions: connect, disconnect, and registerEventListener. RegisterEventListener takes a function pointer which is called each time an event is raised on the device.
    My wrapper DLL exposes connect and disconnect functions via JNI. I can call these functions just fine from my Java code. Now the question... How do I call a Java method from my c++ callback function? I can call a Java method using env->CallXXXMethod(...) from within a function that is accessible to Java but I don't have access to the JNI parameters in my Callback function.
    So how do I call a Java method from a callback function? If this cannot be done then what is the "right way" to handle native event notification with JNI?

    jschell wrote:
    JNI parameters? Meaning what exactly?
    General outline of a callback
    1. Entry
    2. Get the VM, env - there are methods for this
    3. Attach the thread
    4. Get a java object - how depends on what you are doing, but create it or a static reference.
    5. Get the java method
    6. Call the java method.That is exactly correct. The callback function is called from a separate thread so using a cached pointer to JNIEnv, obtained from the original native method, crashes the JVM. The jmethodID and jclass objects (which are needed to call the static Java method) can be cached without problem. The following is the code I used to attach the current thread and call my static method.
    void MyClass::onEvent(int system_id, char* data)
         //get a pointer to the Java Environment
         JNIEnv *env;
         jvm->AttachCurrentThread((void **)&env, NULL);
         //Call the Java method with the newly aquired data
         jstring js = env->NewStringUTF(data);
         env->CallStaticVoidMethod(cls, mid, system_id, js);
    }My last question is about cleanup in this function. When I use NewStringUTF to "convert" my char* to jstring do I need to do anything special to clean up or will the Java garbage collector take care of it since the jstring is being passed to a Java method?
    Thanks for you help

  • Calling more than a Java method from C++

    Hi everyone,
    I haven't found any example with infomation about calling a second Java method from C++,after creating a VM from C++ also.
    Here is the code I'm testing:
    JNIEnv *env;
    JavaVM *jvm;
    JDK1_1InitArgs vm_args;
    jint res;
    jclass cls;
    jmethodID mid;
    jobject jobj;
    char classpath[1024];
    vm_args.version = 0x00010001;
    JNI_GetDefaultJavaVMInitArgs(&vm_args);
    sprintf(classpath, "%s%c%s",
    vm_args.classpath, PATH_SEPARATOR, USER_CLASSPATH);
    vm_args.classpath = classpath;
    res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
    if (res < 0) {
    fprintf(stderr, "Can't create Java VM\n");
    exit(1);
    cls = env->FindClass("Consola");
    if (cls == 0) {
    fprintf(stderr, "Can't find Prog class\n");
    exit(2);
    mid = env->GetMethodID(cls, "<init>", "()V");
    if (mid == 0) {
    fprintf(stderr, "Can't find Prog.main\n");
    exit(3);
    jobj = env->NewObject(cls, mid);
    if (jobj == 0) {
    fprintf(stderr, "Can't find Prog.main\n");
    exit(4);
    jmethodID mid2 = env->GetMethodID(cls, "isVisible", "()Z");
    if (mid2 == 0) {
    fprintf(stderr, "Can't find Prog.main\n");
    exit(5);
    jboolean b = env->CallBooleanMethod(cls, mid);
    All works fine till the last line.
    Folowing message appears in screen running the last code line:
    Runtime error!
    Program: s:\client\mcc_cyg\debg\debug\debgnt.exe
    abnormal program termination
    What to do ?
    Thanks in advance.
    Ignasi Villagrasa.

    There should be examples of this in the JNI tutorial.
    Also suggest a book: essential JNI by Rob Gordon
    Briefly, what you need is a reference to the JVM. (I assume you have this - either because it was given to you when your C code started the JVM, or because it was passed as an argument to your native method.)
    With the reference, you can look up a class, and look up a method, and call the method.
    What about an object reference?
    o You can call a method on an object which was passed to your native method.
    o You can ask one object for a reference to another object.
    o You can call a java constructor, which will return a reference.

  • Calling java method from c function

    Hi,
    I have been through some forums and tutorials, but nothing helps me yet.
    Here's my problem : I want to access java funtion from c function.
    <code java>
    public class MyClass {
    public int oneMethod() {
    return 5;
    </code java>
    <code c++>
    void main(int argc, char *argv[]) {
    // creation of JVM -> no problem
    cls = (env)->FindClass("MyClass");
    if (cls != 0) {
    // it finds the class
    mid = (env)->GetMethodID(cls, "oneMethod", "()I");
    if (mid != 0) {
    // it finds the method
    intReturn = (env)->CallIntMethod(cls, mid);
    printf("Result of oneMethod: %d \n", initReturn);
    </code c++>
    the initReturn gives me 0, and not 5. So what do you think the mistake is ?
    Should I pass by the GetClassObject() funtion, but in this case, what object would I pass in reference since I'm using a call from c to java.
    Thanks a lot for your response, and Happy new Year to all the comunity.

    1. You are - apparently - trying to call a method of a java object.
    2. But you are instead making the call on a class.
    3. You can do one of the following:
    o Pass a reference to the object as you call C.
    o Call some other java method (maybe static) that gets you a reference to a java object.
    o Use JNI to call a java constructor to create a java object.
    o Change your code to get the class object and call a static method.

  • "Deadlock in safepoint code. Should have called back to the VM"

    We experience a VM crash in Safepoint.cpp with the following message:
    # An unexpected error has been detected by Java Runtime Environment:
    # Internal Error (safepoint.cpp:558), pid=5452, tid=1900
    # Error: Deadlock in safepoint code. Should have called back to the VM before blocking.
    # Java VM: Java HotSpot(TM) Client VM (11.0-b16 mixed mode windows-x86)
    # If you would like to submit a bug report, please visit:
    # http://java.sun.com/webapps/bugreport/crash.jsp
    This happens in JRE 1.6.0.11 + Microsoft VS2008 C++, on Windows Server 2003. Happens in a busy customer site once in every few days, cannot reporoduce in the lab.
    There are two relevant threads:
    * Thread A: Created in Java right after system start up. It makes some preparations and then calls C++ code via JNI. In the JNI, Java data types are converted to C++ data types by GetBooleanArrayElements() and GetStringUTFChars(). It remains in C++ forever (until shutdown) and calls back the Java code via JNI every few seconds (that is: the stack contains Java frames, then C++ frames, then from time to time more Java frames and even further C++ frames).
    * Thread B: Created upon need, invokes a C++ function via JNI, converts parameters by GetStringUTFChars() and at return by ReleaseStringUTFChars(). The function may take few milliseconds and up to few minutes to complete, eventually it returns to Java and the thread is deleted.
    At time of crash we see the following:
    * Most of the threads in the system are in state threadblocked - we guess that the VM blocked them for GC.
    * Thread A is the active one. As far as we can tell it is in Java (called back from C++), maybe trying to invoke a C++ function via JNI. It locked and released a mutex ("synchronized") just before the crash (we suspect that while performing this lock its thread's Safepoint state may have changed to callback). The thread state is threadin_native_trans.
    * Thread B is blocked in the JNI trying to return to Java, maybe while invoking ReleaseStringUTFChars(). It's state is threadblocked.
    Another important detail: the crash happens usually certain time (few seconds or even few minutes) after thread B is blocked, and always while thread A is in Java called back from C++. We guess that something caused the Safepoint locking to wait forever while thread B tried to returns to from C++ to Java, and that the activity of thread A make the Safepoint realize that there's a deadlock (so its activity it's not the root cause but a side-effect).
    We always see two mutex / monitors with name UNKNOWN at time of error, and 100% "eden" memory utilization.
    hotspot error dump fragment:
    --------------- T H R E A D ---------------
    Current thread (0x26d51400): JavaThread "DialogicBridge" [_thread_in_native_trans, id=1900, stack(0x28490000,0x284e0000)]
    Stack: [0x28490000,0x284e0000]
    [error occurred during error reporting (printing stack bounds), id 0xc0000005]
    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j telemessage.telephony.DialogicBridge.initializeDialogic(Ljava/lang/String;IIIIIIIIIIIILjava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;IZZ[Z)I+0
    j telemessage.telephony.DialogicBridge$1.run()V+293
    j java.lang.Thread.run()V+11
    v ~StubRoutines::call_stub
    0x2ed00400 JavaThread "<< Call#16207 >> " [_thread_blocked, id=8604, stack(0x2e5c0000,0x2e610000)] // this is thread B
    =>0x26d51400 JavaThread "DialogicBridge" [_thread_in_native_trans, id=1900, stack(0x28490000,0x284e0000)] // this is thread A
    Other Threads:
    0x269f7000 VMThread [stack: 0x26a80000,0x26ad0000] [id=2104]
    0x26a29000 WatcherThread [stack: 0x26cb0000,0x26d00000] [id=9300]
    VM state:synchronizing (normal execution)
    VM Mutex/Monitor currently owned by a thread: ([mutex/lock_event])
    [0x002a8be0] UNKNOWN - owner thread: 0x269f7000
    [0x002a9040] UNKNOWN - owner thread: 0x2ed00400
    Heap
    def new generation total 2816K, used 2707K [0x02730000, 0x02a30000, 0x04e90000)
    eden space 2560K, 100% used [0x02730000, 0x029b0000, 0x029b0000)
    from space 256K, 57% used [0x029f0000, 0x02a14f50, 0x02a30000)
    to space 256K, 0% used [0x029b0000, 0x029b0000, 0x029f0000)
    tenured generation total 30272K, used 17667K [0x04e90000, 0x06c20000, 0x22730000)
    the space 30272K, 58% used [0x04e90000, 0x05fd0d88, 0x05fd0e00, 0x06c20000)
    compacting perm gen total 12288K, used 10995K [0x22730000, 0x23330000, 0x26730000)
    the space 12288K, 89% used [0x22730000, 0x231ecdf8, 0x231ece00, 0x23330000)
    No shared spaces configured.

    Thanks for the advice.
    Eventually (after few days of digging) we found that in certain case we're using the JNIEnv of one thread in the other thread. This leads to sporadic crashes. We managed to simulate the situation in the lab and ensure that fixing the JNIEnv mixture really makes the problem go away.

  • How to implement a call back service?

    hi all,
    i have a method which calls a particular function module. i want to achieve the following two things in the code:
    1. after calling the function module, i want the program flow to get paused - it should wait for a notification from the function module to proceed further.
    2. the function module should send a call back to the method intimating that it is done with the job.
    due to the scenario, synchronous call wil not solve the purpose. i need to use explicit wait and notificaion / call back service.
    any help would be greatly appreciated. thank you.
    rgds,
    ram

    Hello. Have you taken a look at  CALL FUNCTION ... STARTING NEW TASK ...
    See example below. Regards, Peter
    DATA: INFO LIKE RFCSI,
    Result of RFC_SYSTEM_INFO function
          SEMAPHORE(1) VALUE SPACE,    "For WAIT condition
          MSG(80)      VALUE SPACE.    "Handling of exceptions
          RET_SUBRC LIKE SY-SUBRC.     "Handling of SUBRC
    CALL FUNCTION 'RFC_SYSTEM_INFO'
         STARTING NEW TASK 'INFO'
         DESTINATION 'NONE'
         PERFORMING RETURN_INFO ON END OF TASK
         EXCEPTIONS
             COMMUNICATION_FAILURE = 1 MESSAGE MSG
             SYSTEM_FAILURE        = 2 MESSAGE MSG.
    IF SY-SUBRC = 0.
      WRITE: 'Wait for reply'.
      WAIT UNTIL SEMAPHORE = 'X'.
      IF RET_SUBRC <> 0.
         WRITE MSG.
      ELSE.
        WRITE: / 'Destination =', INFO-RFCDEST.
      ENDIF.
    ELSE.
      WRITE MSG.
    ENDIF.
    FORM RETURN_INFO USING TASKNAME.
      RECEIVE RESULTS FROM FUNCTION 'RFC_SYSTEM_INFO'
          IMPORTING  RFCSI_EXPORT = INFO
          EXCEPTIONS
             COMMUNICATION_FAILURE = 1 MESSAGE MSG
             SYSTEM_FAILURE        = 2 MESSAGE MSG.
      RET_SUBRC = SY-SUBRC. "Set RET_SUBRC
      SEMAPHORE = 'X'. "Reset semaphore
    ENDFORM.

  • Drill Down Charts Backed by JAVA

    Hi,
       I am from java background, but I had developed simple projects mostly CURD operations and just a simple chats using Spring Blazeds.
    But now I want to develop  dash board and drill down charts. I have seen some sample , where the data  is an XML which is mapped to flex objects and drill down is done.
    But what I know is just call a remote java method which returns a map or list which I get as a Array collection.
    Is it possible to acehive drill down with such java return type or  does java need to return results only in XML, so drill down can be easy at flex end.
    what is  the best way to do ?
    Almost all the examples comes with an static xml file available for the application, It would be great if  any one can tell how to drill down using a List returned by java or any example  of drill down backed by java.
    Thanks

    You can try using the Data Centric Development (DCD) features of FB 4.0 and try using BlazeDS and LCDS workflows and bind the result to Flex Charts.
    This can help http://sujitreddyg.wordpress.com/category/flex-and-lcds/
    Thanks
    -Sunil

  • JNI, run Java methodes from C++

    I'm trying to understand the JNI for a while, but can't realy figure out how to run a java methode from a C++ code.
    (I've managed to do the oposit; run a C++ methode from Java, but that is not what I need.)
    The thing is that I have a C++ program wich outputs a jpg picture. And I have a Java program wich is using this picture. (Picture size is from 2 - 4KB)
    My temparary (not good) solution for making the picture available for the java code is to have the C program save it to a file, and then make the java program read the file once in a while.
    What I would like is to have the C++ to call the methode updatePicture(byte[] newJPEG) in my javacode. How do I do this?
    Parts of the C++ sourcecode:
    void CExCameraView::OnTimer(UINT nIDEvent){
    static int timercount=0;
         CExCameraDoc* pDoc = GetDocument();
         timercount+=pDoc->mycameraconfig->RefreshInterval ;
         if (timercount<pDoc->mycameraconfig->LoadOverHeads )
              return;
         else
              timercount=pDoc->mycameraconfig->LoadOverHeads;
         ASSERT_VALID(pDoc);
    //grab one image and save it to a jpeg file
    // here I'd like to call the java updatePicture methode (not save as file)
         pDoc->GrabSaveNext(pDoc->myconfig->cmsTimeOut);
    And parts of the java code:
    class ImageHandler {
    JpegImage jpegImage; // class JpegImage extends Image
    public ImageHandler() {
    jpegImage = new jpegImage();
    setParameters();
    public updatePicture(byte[] newJPEG) {
    setImage(newJPEG);
    // lots of other methods
    Pete
    "If we knew what it was we were doing, it would
    not be called research, would it? [Einstein]"

    Well, you seem to be defining a C program with some imbedded java, or a java program with some native C methods. So which is it?
    o If it is a C program, then you have two things to do (with respect to java):
    - Start a java JVM.
    - During your processing, periodically call into your JVM to process data made available by your C program.
    o If it is a java program, then what you want to do -- I guess - is call a native method to start up an asynchronous (C) process, then have that asynchronous
    process periodically call back into java to process results.
    Overview of JNI (which you need to flesh out with some further study):
    o There is the socalled invocation API, which is used to get java started.
    o There is the definition of java native methods, which are then implemented in a C library (DLL on Windows), which library is loaded up at runtime by the java program, allowing the native methods to be called.
    o There are JNI methods available from C that allow you to look up objects and methods, and invoke those java methods.
    Two references:
    o Essential JNI by Rob Gordon.
    o www.swig.org

  • Oracle BI EE 11g – Action Framework - Invoke a Java Method from Action links

    Hello All,
       I have a requirement to save OBIEE 11g report into shared drive. I have created a EJB by using the below link and successfully deployed the application in server(bi_server1) .
    http://www.rittmanmead.com/2010/09/oracle-bi-ee-11g-action-framework-java-ejbs-and-pdf-watermarks/
    When Im trying to call Invoke a Java method, it is showing "No Content" . Can anybody please share with me the sample "ActionFrameworkConfig.xml" file used for Invoke a Java method.
    My OBIEE version is : 11.1.1.7.131017
    Thanks.

    1. check your t3 port no, in my case it's 7001.
    so i changed "<jndi-url>t3://localhost:9704</jndi-url>" to "<jndi-url>t3://localhost:7001</jndi-url>"
    2. if you run obiee 11.1.1.6.0 above, you don't need below.
    <credentialmap>oracle.bi.actions</credentialmap>
    so please drop this line.
    3. restart your server and check there's no error log when loading ActionFrameworkConfig.xml.
    Good Luck !!!

  • JNI - core dump - internal error on linux after calling Java method

    I'm getting a core dump after calling athe main statric method using JNNI.
    On linux.
    I can get the class id correcttly but when I attempt to call the method it craches with an internal error , anyone know why it would crash instead of just not work.
    if(cls)
        main_methodID = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
           printf("Class Found Successfully\n");
      else
        printf ( "cls not found\n");
        return 0;
      if(main_methodID)
              jstring first_str = env->NewStringUTF("The First String");//create string
              jobjectArray args = (jobjectArray)env->NewObjectArray(1,env->FindClass("java/lang/String"), first_str);//new array with 2 elements
                   env->SetObjectArrayElement(args, 2, first_str);//insert the second string into index 1 of the array
              jstring second_str = env->NewStringUTF("The Second String");//create string
              env->SetObjectArrayElement(args, 1, second_str);//insert the second string into index 1 of the array
         env->CallStaticVoidMethod(cls, main_methodID, args);//pass the array to the Java main method
                                  The JAVA method is
      public static void main(String[] args) {
        System.out.println("Main method in Framework");
            Framework framework = new Framework();
                                 

    I see yere points but what I see on linux is it makes it to the constructor of the Java object and somewhere afterwards it bails out, the Java app does work alone. It appears to have problems initializing the JFrame, could there be a problem with the Java inheritance when a JVM is invoked throurgh native invocation??
    Here's some of the Java stuff
    public class Framework extends WindowAdapter {
        public int numWindows = 0;
        private Point lastLocation = null;
        private int maxX = 500;
        private int maxY = 500;
        public Framework() {
            System.out.println("JAVA Framework cnst");//GETTING HERE
            makeNewWindow();
        public void makeNewWindow() {
            System.out.println("JAVA makeWindow"); //GETTING HERE
            JFrame frame = new MyFrame(this); //NOT GETTING HERE!!!!!!!!!
            numWindows++;
            System.out.println("Number of windows: " + numWindows);
            System.out.println("Frame location: " + lastLocation);
            frame.setVisible(true);
            System.out.println("Post Java set frame visible");
        public static void main(String[] args) {
        System.out.println("Main method in Framework");
            Framework framework = new Framework();//GETTING HERE
    class MyFrame extends JFrame {
        protected Dimension defaultSize = new Dimension(200, 200);
        protected Framework framework = null;
        public MyFrame(Framework controller) {
            super("New Frame");
            System.out.println("MyFrame cnst ");//NOT GETTING HERE!!!!!!
            framework = controller;
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            addWindowListener(framework);
            JMenu menu = new JMenu("Window");
            menu.setMnemonic(KeyEvent.VK_W);
           setSize(defaultSize);
    }

Maybe you are looking for

  • Why Can't I Download Elements 7?!?!

    This is EXTREMELY UPSETTING & FRUSTRATING!!! I purchased Elements 7 on-line, and I have LITTERALLY been ALL DAY trying to get this thing to download. The trial version downloaded with no problems. I went ahead and purchased it, seeing that there is n

  • How do I delete itunes library and move library from old windows machine to

    My daughter bought a new macbook and would like to move her itunes library from the windows machine to the mac. I copied it to the mac and moved the existing itunes folder to the trash. By the way, she got 3 free downloads from Apple and they were in

  • Internet explorer 11 is opening multiple blank tab like a recursive tab(worm like attack on browser

    Hi Kindly be of help, my company systems just upgrades to Internet Explorer 11, after the upgrades all the Internet explorer 11 on all the systems are opening multiple tabs of blank pages with an error messages prompt,This has disrupt our working env

  • Configuration Assistants Stops in Infrastructure installation

    hi. I'm installing Oracle Infrastructure for OCS. I installed fine until I met Configuration Assistants many of them are fine but in "OPMN Configuration Assistant - start OPMN" it says "in progressing". what do i do? I was trying to find some tips in

  • Rolling 15 Month

    Hello All, I'm trying to create a dynamic filter for a report which shows a rolling 15 months worth of data by default. For example, the current date is the 28/07/2008 I would like to show everything in the report for: = 01/07/2008 AND <= 30/10/2009S