I m working on a swing based java application which uses 3rd party library functions by loading DLL .
Some functionality in the DLL calls exit(1)
which is closing the entire java application. Is there any solution which can keep my JVM aliv开发者_运维百科e if it encounters with exit(1)
. I don't have access to the C source code.
A 3rd party library that calls System.exit()
is broken. A 3rd party library that calls the C exit()
library method is even more broken. Lodge a bug report with the vendor and consider switching to a better alternative.
You could possibly stop System.exit()
from working by using a security manager that blocks the call. But I'm not sure that a call coming from a DLL would be controlled by the security manager.
If you can't change the way the DLL behaves, and can't use it in a manner where it won't call exit()
, your best bet might be invoke its functionality in the context of another process. It will then be this other process that goes down, and your main process will not be affected.
Whether this is a practical workaround in your case, I don't know.
exit() is exit(), nothing you can do about that. Complain to the vendor of the DLL.
精彩评论