简体   繁体   中英

What is the difference between regular quit and eclipse terminate?

What happens is that when I press ALT+F4(Win) or CMD+Q(Mac) to quit the program, the program will hang until I force quit it using task manager.

However, when I terminate the program using eclipse's terminate button, the program shutdowns nicely without hanging.

What is the difference between the two methods of closing the application?

For example, is it because threads in the application do not terminate on its own when we do a regular quit (ie ALT+F4) whereas in eclipse, threads are "forced" to terminate?

Edit

I just realised System.exit(0) is equivalent to "force quit" (ie no hangs). Is there any method where I can detect when ALT+F4 or CMD+Q is pressed and from there, the system/ program will do a System.exit ?

Edit 2

I have done the following but the hang still persists:

  1. I have tried changing all of my threads into Daemon.

  2. I have used jvisualvm to see which threads are still running after ALT+F4 is pressed. I do realise some "Pool-i Thread-i" threads are still running. ( Is there any way to pin-point which part of the codes represents "Pool-i Thread-i" ? I suspect these threads are created by one of the third-party libraries I have used.)

  3. In my threads/ callables, I have a console output at the very end of the thread and the console output will display when I ALT+F4 the program. For example,

public Void call() {
    while(true) {

    }
    System.out.println("Thread has finished");
}

The console will print " Thread has finished " when I press ALT+F4 , hence I assume these threads have terminated correctly.

The Eclipse terminate button performs basically what force quit in Task Manager does -- it terminates the process forcibly. Alt+F4 or CMD+Q notifies the program to be terminated, which should response in a timely manner; if it doesn't, you'll get the unresponsive program alert in Windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM