Our programming model is like this:
The c code is to capture the real-time events(very frequent) of the system and java code runs as a server to receive the request. When there is an event captured by the c code, we need to send request to java code and wait for the reply. I have tried JNI to call java from c, but it seems that it will stuck after running for several seconds. JNI needs to initialize jvm and search the handler in the class file. Is there any better way to communicate between c and java? Can I compile java code into binary and link it with the c code?
Thanks
You may want to look into using sockets if there is a nice producer-client/consumer-server paradigm involved. That way the C-code is running in the background and pushes info to the Java service over a socket connection, and the Java services in-turn sends replies back to the C-code. You could also look into using FIFO’s or named pipes for communication as well, but sockets, at least locally on a machine, tend to be pretty fast and efficient on most platforms.
Also, the Java service can start-up the C-code on-launch if you need to work that way, or vice-versa (i.e, the C-code can fork off a VM and start the Java service).