views:

184

answers:

2

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

A: 

Posting the VM crash report should help.

rich
A: 

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.

jitter