dcsimg
Call back from a C thread to Java
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nithya_Vijayakumar
Posted On:   Thursday, October 28, 2004 12:58 PM

Hi, I am accessing a C++ class through JNI. I am creating a C++ instance in a native method called instantiate and passing back the pointer to java. Whenever the java application wants to use this C++ library, the pointer is also passed along with other parameters to the native code. This works fine. But I am facing problem with one particular method in the library which creates pthreads. ie. When Java application calls this C++ method, it creates many threads which monitor some events. The C++ function returns back to java as soon as these threads have been created but does not wait for them complete. I would like a way for these pthreads to call back a handler method in the java instance when the event   More>>

Hi,



I am accessing a C++ class through JNI. I am creating a C++ instance in a native method called instantiate and passing back the pointer to java. Whenever the java application wants to use this C++ library, the pointer is also passed along with other parameters to the native code. This works fine. But I am facing problem with one particular method in the library which creates pthreads. ie. When Java application calls this C++ method, it creates many threads which monitor some events. The C++ function returns back to java as soon as these threads have been created but does not wait for them complete.



I would like a way for these pthreads to call back a handler method in the java instance when the events being monitored are completed. I tried using Global references, but since there is no env (as the function which created the threads has returned), I don't know how to call the Java handler back? is it possible to do this with JNI? if yes, can you please provide me an example. I am willing to provide my source code and give more details about what the problem is.



Thanks,

Nithya

   <<Less
About | Sitemap | Contact