处理 JNI 崩溃

发布于 2024-08-16 02:34:31 字数 104 浏览 5 评论 0原文

我有一个包含遗留 C 代码的 dll,我通过 JNI 调用此 dll,但有时 C 代码崩溃并导致 JVM 终止。有没有办法避免 JVM 崩溃?我可以处理 JNI 故障并让 JVM 生存吗? :)

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? :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁对谁错谁最难过 2024-08-23 02:34:31

正如 Timo 所说,除了使 JNI 代码健壮之外,您别无选择。如果您不能这样做(例如,如果您没有源代码),那么也许您可以寻求进程间解决方案。将 JNI 代码放在单独的服务器进程中,进行 RMI 或 HTTP 调用。如果崩溃,请重新启动“服务器”,但主 JVM 仍然存在。显然,这会带来性能开销,并且复杂性也会增加,但也许您能负担得起?

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?

百思不得你姐 2024-08-23 02:34:31

如果是 C 代码崩溃,那么防止它带走 JVM 的唯一方法就是首先防止 C 代码崩溃。这是编写 JNI 代码时遇到的主要危险/问题之一,因为与纯 Java 编写的代码相比,它使 Java 和 C 的组合更加脆弱。

If it's the C code that is crashing, then the only way to prevent it from taking the JVM with it is to prevent the C code from crashing in the first place. That's one of the main dangers/problems that you get when writing JNI code as it makes the combination of Java and C somewhat more fragile compared to something that is written in pure Java.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文