jna 对 shutdown hook 中的 kernel32.CreateToolhelp32Snapshot 的调用导致虚拟机崩溃

发布于 2024-08-10 23:55:56 字数 448 浏览 1 评论 0原文

如果线程使用

Runtime.getRuntime().addShutdownHook();

jna 方法调用来设置关闭钩子:

kernel32.CreateToolhelp32Snapshot (0x00000002, 0)

它会使 VM 崩溃。 如果我在挂钩中调用相同的方法

WindowListener.windowClosing()

,该调用不会使虚拟机崩溃。

知道为什么吗?

如果有任何用处,我可以发布部分虚拟机崩溃错误报告。

编辑:请参阅 pastebin 上的虚拟机崩溃报告

If a thread sets a shutdown hook using

Runtime.getRuntime().addShutdownHook();

calls via jna the method:

kernel32.CreateToolhelp32Snapshot (0x00000002, 0)

it crashes the VM.
If I call the same method in the

WindowListener.windowClosing()

hook, the call does not crashes the VM.

Any idea why?

I can post part of the VM crash error report if it could be of any use.

edit: see the VM crash report on pastebin

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

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

发布评论

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

评论(2

时光清浅 2024-08-17 23:55:56

发布虚拟机崩溃报告应该会有所帮助。

Posting the VM crash report should help.

绻影浮沉 2024-08-17 23:55:56

将部分崩溃报告发布在pastebin 或类似的网站上,也许有些人可以从中获取一些信息。

好吧,我不确定,但是如果您阅读 addShutdownHook()

关闭挂钩在微妙的时间运行
在虚拟机的生命周期中
因此应该进行防御性编码
他们应该,在
特别地,可以写成
线程安全并避免死锁
尽可能。他们还应该
不要盲目依赖服务
可能已经注册了自己的关闭
钩子,因此可能自己在
关闭的过程。
....
关闭挂钩也应该完成
他们的工作很快

...

这些让我得出这样的结论:也许调用这样的方法要么需要 JVM 中不再可用的服务,要么这个调用花费的时间太长。

Post part of the crash report on pastebin or the like maybe some can get some info out of that.

Well I don't know for sure but if you read the java doc for addShutdownHook()

Shutdown hooks run at a delicate time
in the life cycle of a virtual machine
and should therefore be coded defensively.
They should, in
particular, be written to be
thread-safe and to avoid deadlocks
insofar as possible. They should also
not rely blindly upon services that
may have registered their own shutdown
hooks and therefore may themselves in
the process of shutting down.
....
Shutdown hooks should also finish
their work quickly
.
...

these leads me to the conclusion that maybe calling such a method either needs services from the JVM that aren't available anymore or that this call takes too long.

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