Occasional InterruptedException when quitting a Swing application

前端 未结 17 1143
心在旅途
心在旅途 2020-12-05 04:55

I recently updated my computer to a more powerful one, with a quad-core hyperthreading processor (i7), thus plenty of real concurrency available. Now I\'m occasionally

17条回答
  •  庸人自扰
    2020-12-05 05:33

    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.

提交回复
热议问题