Hi, I am also interested in knowing the answer to this question. I have thought of ways, but none are very good regarding performance. 1. The c program invokes the jvm and runs a java program which listens for connections over socket. Then this c program communicates with the java using sockets. 2. Sim to first. Only the communication is thru shared data files.
Originally posted by Shubhrajit Chatterjee: 1. The c program invokes the jvm and runs a java program which listens for connections over socket. Then this c program communicates with the java using sockets.
That is what CORBA does, of course, with all the bells and whistles.
Joined: Nov 22, 2008
Hi Gali and Shubhrajit, I think the network option is still the best, even if not very good in terms of perf. If you go for that solution, consider using XML/RPC or SOAP. Another solution would be to use JNI (Java Native Interface). Using the invocation API (see below), your C code can create a java virtual machine that communicates with your application. The initialisation code should look like that:
Once created, you attach your thread to the JVM using the AttachCurrentThread method. You can then call methods on java objects using the GetObjectClass, GetMethodID and CallXXXMethod methods on the JVM environment. You can then detach your thread from the VM once finished. See the tutorial on JNI on the Sun website: http://java.sun.com/docs/books/tutorial/native1.1/ The tutorial mentions that the JDK only supports attaching native threads on Win32. This was true at the time of writing but it is now possible on other systems (e.g. Solaris, Linux, etc...) as native threads are now available on those other OS. Hope this helps, Beno�t [This message has been edited by Beno�t d'Oncieu (edited December 19, 2001).]