JDK-6407552 : AWT/plugin is not terminated if a window is periodically shown from Timer
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Cannot Reproduce
  • OS: windows
  • CPU: generic
  • Submitted: 2006-04-03
  • Updated: 2014-12-18
  • Resolved: 2014-10-07
Related Reports
Relates :  
Relates :  
Description
Steps to reproduce the problem:

1. Compile the following applet:

import java.awt.event.*;
import java.awt.*;

public class LeakApplet extends Applet {

    public void init() {
        final Timer t = new Timer(400, new ActionListener() {
            JDialog dlg = null;

            public void actionPerformed(ActionEvent e) {
                if (dlg == null) {
                    dlg =  new Dialog((Frame)null, false);
                    dlg.setBounds(100, 100, 100, 100);
                    dlg.setVisible(true);
                } else {
                    dlg.dispose();
                    dlg = null;
                }
            } // actionPerformed
        }); // Timer class

        Button b = new Button("Start");
        b.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                t.start();
            } // actionPerformed
        }); // addActionListener
	
        add(b);
    } // init
} // LeakApplet

2. Launch this applet in Mozilla or Mozilla Firefox browser using HTML file:

<html>
<body>
<h2> Test </h2>
<applet code="LeakApplet.class" width="200" height="200"></applet>
</body>
</html>

3. Open another, blank window of the browser (ctrl+N by default). It can be minimized or not.

4. Switch to the first browser window and press 'Start' button in applet.

5. You should see a dialog shown and then hidden periodically. Close the browser window that contains the applet while leaving another blank browser window open or minimized.

6. Sometimes a dialog is left on the screen and it can't be closed any way other than by terminating the whole browser process (that's why another Mozilla window is used).

I don't know if the same problem can be reproduced on linux/solaris or in other browsers. However, I suspect this is a general AWT threading issue.

Comments
Cannot reproduce with latest builds (compiled applet is attached). Please reopen the issue if you find reproducible case with latest builds.
07-10-2014

EVALUATION From AWT side I dont's any way how this 'zombie' dialog may appear. Indeed, if Java Plugin teminates the applet with System.exit() call, the whole JVM must exit; if Java Plugin makes just disposes all the toplevels, the swing timer must prevent AWTAutoShutdown from triggering (see 6553268 as an example), and the dialog must continue its flashing. That's why I'm dispatching this CR to Java Plugin team for further investigation. Note, that the new Java Plugin implementation may behave completely different with this test.
09-07-2008

EVALUATION After some further investigation I have noticed the following exception in Java Console: Exception in thread "TimerQueue" java.lang.IllegalMonitorStateException at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(Unknown Source) at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(Unknown Source) at java.util.concurrent.locks.ReentrantLock.unlock(Unknown Source) at java.util.concurrent.DelayQueue.take(Unknown Source) at javax.swing.TimerQueue.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Thread dump, however, doesn't expose any problems: Group main,ac=9,agc=1,pri=10 AWT-Shutdown,5,alive AWT-Windows,6,alive,daemon traceMsgQueueThread,5,alive,daemon CacheCleanUpThread,5,alive,daemon AWT-EventQueue-0,6,alive Thread-14,5,alive Group Plugin Thread Group,ac=3,agc=0,pri=10 AWT-EventQueue-1,6,alive ConsoleWriterThread,6,alive,daemon TimerQueue,5,alive,daemon
09-07-2008

EVALUATION The bug can't be reproduced with appletviewer, thus, something gets wrong while running AWT from plugin. I suspect that after the browser window is closed, the toolkit thread is still alive but all the dispatch threads and event queues are disposed. That's why a dialog is shown but can't be operated in any way. As I know, when the browser window is closed, plugin sends a closing event to the applet. Then, all other top-level windows are destroyed and that would trigger AWTAutoShutdown to awaken and terminate AWT completely. However, something here doesn't work, and it should be investigated deeper.
03-04-2006