I have a dll that contains legacy C code, I call this dll via JNI, but sometimes the C code crashes and causes the JVM to terminate. Is it there a way to avoid JVM crash? Can I handle the JNI fault and let the JVM survive? :)
The JNI is a native programming interface. It allows Java code that runs inside a Java Virtual Machine (VM) to interoperate with applications and libraries written in other programming languages, such as C, C++, and assembly.
Java Native Access (JNA) is a community-developed library that provides Java programs easy access to native shared libraries without using the Java Native Interface (JNI). JNA's design aims to provide native access in a natural way with a minimum of effort. Unlike JNI, no boilerplate or generated glue code is required.
Jump if not equal/ Jump if not zero. Description: Jumps to the destination label mentioned in the instruction if the ZF is 0, else no action is taken.
As Timo has said, you have no real alternative but to make the JNI code robust. If you can't do that (for example if you don't have the source) then perhaps you could go for an inter-process solution. Put the JNI code in a separate server process, make RMI or HTTP calls across. If it crashes, restart the "server" but main JVM survives. Obviously there's a performance overhead, and an increase in complexity, but maybe you can afford this?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With