Whenever you call C or C ++ code with Java through JNI or its equivalent, you run the risk of destabilizing the Java platform due to memory management and / or thread safety issues on the C / C ++ side.
Before moving on to the JNI route, etc., I think you should consider other alternatives:
- Derive Java from the equation and fully implement it in C ++ (or C ++ / C #, like someone else).
- Create a C ++ command-line application that performs the task you need to complete using your own library, and launch the application using one of the
java.lang.Runtime.exec methods. - Create a βserverβ shell in C ++ for the library that provides the functionality you need as a custom protocol, and encode a conversation with the server on the Java side using HTTP, raw Sockets, Pipes, or any other transport layer.
All alternatives have disadvantages, but JNI / JNA and the like; see first paragraph.
EDIT: when you decide to use JNI / JNA in the system, there are likely to be long-term consequences. In addition to the stability problem, you must consider portability (whether working with the native library will work on Windows, Linux, etc.), create problems (it is difficult to create your own libraries in Ant, etc.), problems with platform versions (will being updated on Java 7 is something broken?), developer skills ("Joe", who did the JNI integration, is gone - who else knows Java, C ++ and JNI?). The sum of these problems (IMO) is more significant than the time required for initial development.
source share