Hello I have a little big problem in JavaFX application with terminating java process when all brower windows are closed. I was trying to handle Stage.setOnHiding or .setOnCloseRequest and terminate all running threads and do Platform.exit in the handler body, but with no luck. First of all none of handlers setOnHiding and setOnCloseRequest are invoked when I'm closing browser. Also setting Platform.setImplicitExit(true) does not cause java process to terminate when browser is closed - this works only sometimes. Sth prevents javafx process from being killed after web browser is closed. How can I detect what ?
For me, JavaFX applications hosted in a browser always terminate automatically when the browser is closed.
You should implement Application.stop() to detect the application shutdown event.
Stage level methods setOnCloseRequest and setOnHiding are not the right methods for detecting an application level shutdown event.
Related
I'm developing a Java desktop application for Windows and I'm trying to implement the Windows Restart Manager. I'm successfully receiving the Windows messages for exiting the application and when I send them manually, it just works and the application shut downs.
When I do it as part of the uninstall process, the shutdown procedure in my application runs and I can even see it calls System.exit(0) but even after that, there's a process that doesn't stop. My Java application is packaged into an executable file using launch4j in case that's relevant.
The way I know System.exit(0) is being called is because I'm dumping debugging information to a file and I print out that System.exit(0) is about to be call and I can see that whether the application succeeds or fails on properly shutting down.
Using the Process Explorer I can see the javaw.exe sub-process and when the exit procedure happens, that goes away, but the parent process remains. While the is running, it looks like this:
and after the failed exit, it looks like this:
If I have a remote debugger connected to the process, at this point, the debugger gets disconnected.
What could be causing this?
I'm close to being convinced this is a bug in launch4j, so, I reported it here: https://sourceforge.net/p/launch4j/bugs/185/
Why is it recommended to use setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); if there are ways to explicitly close the frame?
Calling setDefaultCloseOperation(EXIT_ON_CLOSE) causes the application to exit when the application receives a close window event from the operating system. Pressing the close (X) button on your window causes the operating system to generate a close window event and send it to your Java application. The close window event is processed by the AWT event loop in your Java application which will exit the application in response to the event. If you do not call this method the AWT event loop may not exit the application in response to the close window event but leave it running in the background.
JFrame.EXIT_ON_CLOSE stops the application from running in background. For example, if you didn't use JFrame.EXIT_ON_CLOSE, if your application has an active database connection, it will stay connected. To check this, you can open task manager and see the jar file still running even if its window is no longer visible.
My project is basically a Communication client like lync which is developed in JAVA for front end (GUI) and uses platform specific native (C or C++) code for running services.
Now, on Linux, (Ubuntu 12.04), once the JAR application is invoked, it loads all the native code shared libraries and the UI thread starts executing. Any action done in the UI will throw an event to the native code which is in C. So currently i need to debug a crash in a C/C++ user library which is triggered when i do something in a UI drop down.
I am using GDB, to attach to the PID of the process , (sudo gdb -p ), all the symbols are loaded and i am able to set a breakpoint to a function say A() in the library.After continue command in GDB, i select the instance from UI Dropdown and breakpoint is hit at Function A(). At this moment, my ubuntu machine hangs and no keyboard interrupts are working. I am only able to move my mouse pointer but cannot click on anything.
However, to verify that kernel is not down, i can ping the machine and even SSH is possible. Once the same GDB is invoked by SSH the above problem is not encountered. May anyone please help me out here as to why UI or X11 process hangs during the above scenario.
PS: Yes there are lot of threads running, it might be a thread deadlock situation but it does not happen when GDB is invoked by SSH terminal.
Thanks and Regards,
Indra
why UI or X11 process hangs during the above scenario
As Mark Plotnick correctly pointed out, the X11 process does not hang. Rather, it grabs the keybard (all keyboard events are dispatched to it), and can not release that grab (it is stopped by GDB before it reaches the release point).
There are two common solutions:
ask the application to not do the keyboard grab (as Mark said), or
debug the application from a separate machine (this can even be done on single physical machine: just run the application inside a VM).
P.S. Why do application menues grab keyboard? Because hitting Esc usually dismisses the menu, and they want to see that Esc regardless of whether the application has input focus or not).
Whenever I use my webcam application within the main form, the program does not closed and still appearing in the task manager or in the bottom right of the Netbeans saying that it is still running even if I clicked STOP or close my form. It only occurs when I access my Webcam snapshot application from my main form button.
I've read so many answers but it doesn't give me the solution.
My guess in my problem is the following:
It is still running because it will not terminate unless all non-daemon threads (my webcam thread?) are closed.
OpenCV libraries' fault?
Please refer to my first stackoverflow question link : MY PROBLEM.java
Thank you,
I have a problem.
Sometimes when I close my Java applet using the "Close button" in the upper right corner, the console freezes and becomes nonrespondable. The Java process does not shutdown and proceeds to use the maximum of a CPU.
It is only in one of ten times that this happends. It is also not dependant on browsers.
I have made sure that all my threads are properly shutdown along with my threadpool executors.
This is also only happening in applet mode. When I run this in Netbeans, I have never encountered this problem.
I am using Netbeans on Windows.
What could be the reason for the Java console to be hanging like that ?
And how can I determine what the causes of this hanging could be ?
Run your applet in debug more (see here how to do it in Eclipse).
Create a remote debug launch config (see link above).
Close the applet
When the bug happens, start the remote debug launch and pause the whole VM. Now you can inspect the threads to see what happens.