title: Occasional InterruptedException when quitting a Swing application
body: <p>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 <em>occasionally</em> getting the following error when quitting (<code>System.exit(0)</code>) an application (with a Swing GUI) that I'm developing:</p>
  
  <pre><code>Exception while removing reference: java.lang.InterruptedException
  java.lang.InterruptedException
          at java.lang.Object.wait(Native Method)
          at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118)
          at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134)
          at sun.java2d.Disposer.run(Disposer.java:125)
          at java.lang.Thread.run(Thread.java:619)
  </code></pre>
  
  <p>Well, given that it started to happen with a more concurrency-capable hardware, and it has to do with threads, and it happens occasionally, it's obviously some kind of timing thing. But the problem is that the stack trace is so short. All I have is the listing above. It doesn't include my own code at all, so it's somewhat hard to guess where the bug is.</p>
  
  <p>Has anyone experienced something like this before? Any ideas how to start solving it?</p>
  
  <p><strong>Edit:</strong> Since quitting a Swing application with <code>System.exit(0)</code> may be "unclean", but I don't want to set the main frame to <code>EXIT_ON_CLOSE</code> because I want to ensure that there's nothing critical going on when the application quits, I added a mechanism so that it executes the main frame's <code>dispose()</code> method before calling <code>System.exit(0)</code>. So it should be pretty clean now, but the occasional exception still happens. It happens after the <code>System.exit(0)</code> has been called; <code>dispose()</code> works with no problems. That is, it must be coming from a shutdown hook:</p>
  
  <pre><code>mainFrame.dispose(); // No problem! After this returns, all visible GUI is gone.
  // In fact, if there were no other threads around, the VM could terminate here.
  System.exit(0); // Throws an InterruptedException from sun.java2d.Disposer.run
  </code></pre>
  
  <p>I even tried explicitly disposing all <code>Window</code>s by looping through <code>Window.getWindows()</code> array (it contains ownerless <code>Dialog</code>s and such), but it made no difference. This issue seems to have little to do with "cleanness" (i.e. explicitly releasing native screen resources before quitting). It's something else, but what?</p>
  
  <p><strong>Edit 2:</strong> Setting the default close operation to <code>EXIT_ON_CLOSE</code> made no difference. <a href="http://www.google.com/search?q=sun.java2d.Disposer.run(Disposer.java:125)" rel="noreferrer">http://www.google.com/search?q=sun.java2d.Disposer.run(Disposer.java:125)</a> finds a few bug reports, so maybe this indeed is a bug in Sun's Java2D implementation. I could imagine that bugs like this can go unfixed for a long time, because they're pretty harmless in practice; an exception from a shutdown hook hardly hurts anyone else. Given that this happens in a GUI app, the exception is not even noticed unless the <code>stderr</code> is directed to a console or log.</p>