Occasional InterruptedException when quitting a Swing application Occasional InterruptedException when quitting a Swing application multithreading multithreading

Occasional InterruptedException when quitting a Swing application


Your Disposer is blocked in a call to remove() (removing the next platform native resource). This means that the disposer thread (a daemon thread) is not being shutdown naturally when the VM exits (which you should expect since you are terminating it via System.exit()).

You have a non-daemon thread in your application which is keeping the VM from exiting when all your swing windows have been disposed.

Solution: find it and cause it to exit.

Normally a swing application exits gracefully if all of its swing windows have been disposed of, for example, this program will pop a window then exit once it is closed (all with no call to System.exit()):

public static void main(String args[]) throws Exception {    JFrame jf = new JFrame();    jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);    jf.setVisible(true);}

You might also try running the garbage collector before exiting, just for kicks.


If you are using swing application then first call System.gc() and then call dispose() method. I think it will work fine.. I also use this.

Would like to up-vote this but I need more rep. This solution worked for me although I cannot find the explanation why and my co-worker also says it makes no sense.

I have 1.7 and a swing app that I have created, it reads in a file, rearranges the contents and then outputs to a file. has a run and quit button. uses preferences API, writer, reader, and a few other things. Upon opening and closing the app (without System.gc()) immediately only two times successively will return this same Exception as stated above. but with System.gc() right before dispose() I cannot get the Exception to throw again.


System.exit() probably isn't the cleanest way of closing down a Swing based app

Can't you set your main frame to EXIT_ON_CLOSE:

mainFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE )

Then set it to invisible?

Related Q here; System.exit(0) in java