System.exit is not exiting?

Hey everyone, I’ve run into a weird problem with System.exit, basically I have this code:


    public void windowClosing(WindowEvent e) {
        System.err.println("WindowClosing");
        System.exit(0);
    }

When I close the window windowClosing IS called because WindowClosing is written to the console, however the program does not exit and I can only terminate it by using Task Manager, does anyone know what could be causing this problem?

SecurityException is also not thrown when System.exit is called, Running Oracle JRE7, Windows 8.1

In that case, you probably have still some Threads running. Set the Threads as deamon if you want them to close on System.exit.

That cant be the problem since I just wrote this program and it exits after 1 second even though I have 10 non-daemon threads running.


public static void main(String[] args) throws Throwable {
        for (int i = 0;i<10;i++) new Thread(new Runnable() {

            public void run() {
                while (true) {
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(TestExit.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }).start();
        
        Thread.sleep(1000);
        System.exit(0);
    }