Unloading dll rxtx before exit to avoid jvm crashes or hide hs_err_pid.log files

情到浓时终转凉″ 提交于 2019-12-25 05:25:12

问题


Well, I'm on a project that uses rxtxSerial.dll (very buggy by the way).

Anyway, I made a modification on the GUI to make it more user-friendly, initially the program shows up the main window and it's possible to open some other frames where the user can monitor certain devices designed by the company I work for. So when the user wanted to close the hole program and any windows where openend it showed up a dialog asking for the user close the oppened windows himself and then close the program, that was really ugly so I thought: let's make it better; and that's what I made:

when JDialogs that use serial communication are opened I just save a reference for it for future use if the user prompt to close the program than before exit, the program performs the following code to ensure that the respective listeners are called like stop reading from the serial port:

    for (Window w : openedWindows)
    {
        w.getToolkit().getSystemEventQueue().postEvent(
            new WindowEvent(w, WindowEvent.WINDOW_CLOSING));
    }

The program doesn't crash when the dialogs are closed by the user so there is no problem on the WindowListeners that are responsible for shuting the communication down, and sometimes it crashes when prompt to close while online windows are oppened (in serial communication aspect), actually the crash itself is not visible for the user (just if he look into program's folder the hs_err_pid.log files) and happens about 20% of the closes with online windows. The crash in hs_err are like: siginfo: ExceptionCode=0xc0000005, writing address 0x17adfa88 so what I suppose it's happening is that the dll tries to write to java's memory after it was already closed so the jvm crashes (correct me if I'm wrong).

What I want is a way to not generate those error log files, it can be made fixing the problem or just a way to hide those files, if possible that I thing the answer is not.

One of the possible fixes I thought possible is to force unload the dll before shutting down the jvm itself or "ask for" unload the dll and wait until it's unloaded.

Any ideas?

Thanks in advance.


回答1:


Solved my problem migrating from rxtx to jSSC: http://code.google.com/p/java-simple-serial-connector/

Now everything is working smooth! Integrated dlls into .jar for Windows, linux, mac and solaris with system auto-detection.

saved my a lot of work!

Still have no clear reason for those crashes.



来源:https://stackoverflow.com/questions/12689736/unloading-dll-rxtx-before-exit-to-avoid-jvm-crashes-or-hide-hs-err-pid-log-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!