[icedtea-web] RFC: Patch to fix applet exit

Deepak Bhole dbhole at redhat.com
Mon May 2 08:56:25 PDT 2011


Hi,

This patch addresses an issue cause by the tg.stop() call in
PluginAppletViewer.appletClose().

With the recent classloader sharing changes, applets from the same page
have the same threadgroup. As a result if 2 copies are opened and one is
closed, the other one stops too.

With this patch, tg.stop() is no longer called and instead, the plugin
will halt the VM after the last applet to guarantee that resources are
freed eventually (the tg.stop was added because not all applets exit
nicely on stop/dispose).

ChangeLog:
2011-05-02  Deepak Bhole <dbhole at redhat.com>

    * plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
    (appletClose): Do not try to stop threads, now that the loader is shared
    and the thread group for applets on a page is identical. Call dispose from
    invokeAndWait.
    (appletSystemExit): Exit the VM when called.

Okay for HEAD and 1.1?

Cheers,
Deepak
-------------- next part --------------
diff -r d57169ddb76a plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
--- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java	Fri Apr 29 16:58:05 2011 -0400
+++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java	Mon May 02 11:40:55 2011 -0400
@@ -1625,11 +1625,17 @@
 
                 appletShutdown(p);
                 appletPanels.removeElement(p);
-                dispose();
+                
+                try {
+                    SwingUtilities.invokeAndWait(new Runnable() {
+                        public void run() {
+                            dispose();
+                        }
+                    });
+                } catch (Exception e) { // ignore, we are just disposing it
+                }
 
-                if (tg.activeCount() > 0)
-                    tg.stop();
-
+                // If there are no more applets running, exit the VM
                 if (countApplets() == 0) {
                     appletSystemExit();
                 }
@@ -1640,12 +1646,10 @@
     }
 
     /**
-     * Exit the program.
-     * Exit from the program (if not stand alone) - do no clean-up
+     * This function should be called to halt the VM when all applets are destroyed.
      */
     private void appletSystemExit() {
-        // Do nothing. Exit is handled by another
-        // block of code, called when _all_ applets are gone
+        System.exit(0);
     }
 
     /**


More information about the distro-pkg-dev mailing list