0

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.

HericDenis
  • 1,364
  • 12
  • 28
  • 1
    Check this http://stackoverflow.com/questions/4307154/unloading-dll-in-java – Konstantin V. Salikhov Oct 02 '12 at 12:01
  • Thanks @KonstantinV.Salikhov but I already took a look on that, could'n extract anything usefull. – HericDenis Oct 02 '12 at 12:04
  • If you have a buggy DLL or shared library it may be worth running it in a separate JVM. This way the process with the DLL can be restarted as required with minimal impact on your main program. – Peter Lawrey Oct 02 '12 at 12:05
  • @KonstantinV.Salikhov actually, now I looked again for it, I didn't notice the links before, I'm reading those maybe I get something on that. But the problem is, even if I am able to ask GC to collect the library, how will I know if it was already unloaded? – HericDenis Oct 02 '12 at 12:09
  • @PeterLawrey, that's not the main problem, I could make it work nice while normal program execution, the problem is just the log file that is generated sometimes when the program is closed. The program operation itself has no problem. – HericDenis Oct 02 '12 at 12:12

1 Answers1

0

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.

HericDenis
  • 1,364
  • 12
  • 28