7011442: AppletClassLoader.java needs to avoid spurious wakeup
authordcherepanov
Thu, 20 Jan 2011 14:29:03 +0300
changeset 7956 34a05c4d244f
parent 7955 4faac2af1f6e
child 7957 900a9e8d6c4e
7011442: AppletClassLoader.java needs to avoid spurious wakeup Reviewed-by: anthony
jdk/src/share/classes/sun/applet/AppletClassLoader.java
--- a/jdk/src/share/classes/sun/applet/AppletClassLoader.java	Thu Jan 20 14:28:40 2011 +0300
+++ b/jdk/src/share/classes/sun/applet/AppletClassLoader.java	Thu Jan 20 14:29:03 2011 +0300
@@ -663,13 +663,15 @@
                     // set the context class loader to the AppletClassLoader.
                     creatorThread.setContextClassLoader(AppletClassLoader.this);
 
-                    synchronized(creatorThread.syncObject)  {
-                        creatorThread.start();
-                        try {
-                            creatorThread.syncObject.wait();
-                        } catch (InterruptedException e) { }
-                        appContext = creatorThread.appContext;
-                    }
+                    creatorThread.start();
+                    try {
+                        synchronized(creatorThread.syncObject) {
+                            while (!creatorThread.created) {
+                                creatorThread.syncObject.wait();
+                            }
+                        }
+                    } catch (InterruptedException e) { }
+                    appContext = creatorThread.appContext;
                     return null;
                 }
             });
@@ -854,14 +856,16 @@
 class AppContextCreator extends Thread  {
     Object syncObject = new Object();
     AppContext appContext = null;
+    volatile boolean created = false;
 
     AppContextCreator(ThreadGroup group)  {
         super(group, "AppContextCreator");
     }
 
     public void run()  {
-        synchronized(syncObject)  {
-            appContext = SunToolkit.createNewAppContext();
+        appContext = SunToolkit.createNewAppContext();
+        created = true;
+        synchronized(syncObject) {
             syncObject.notifyAll();
         }
     } // run()