changeset 4369:18b883ed2b58

6903354: deadlock involving Component.show & SunToolkit.getImageFromHash Reviewed-by: art, bae
author ant
date Fri, 04 Dec 2009 15:07:15 +0300
parents 84218580baac
children cc409c51b108 dc9dcb8b0ae7
files jdk/src/share/classes/sun/awt/SunToolkit.java
diffstat 1 files changed, 21 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/share/classes/sun/awt/SunToolkit.java	Wed Dec 02 17:26:23 2009 +0300
+++ b/jdk/src/share/classes/sun/awt/SunToolkit.java	Fri Dec 04 15:07:15 2009 +0300
@@ -800,9 +800,9 @@
     }
 
 
-    static SoftCache imgCache = new SoftCache();
+    static final SoftCache imgCache = new SoftCache();
 
-    static synchronized Image getImageFromHash(Toolkit tk, URL url) {
+    static Image getImageFromHash(Toolkit tk, URL url) {
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
             try {
@@ -830,32 +830,36 @@
                     sm.checkConnect(url.getHost(), url.getPort());
             }
         }
-        Image img = (Image)imgCache.get(url);
-        if (img == null) {
-            try {
-                img = tk.createImage(new URLImageSource(url));
-                imgCache.put(url, img);
-            } catch (Exception e) {
+        synchronized (imgCache) {
+            Image img = (Image)imgCache.get(url);
+            if (img == null) {
+                try {
+                    img = tk.createImage(new URLImageSource(url));
+                    imgCache.put(url, img);
+                } catch (Exception e) {
+                }
             }
+            return img;
         }
-        return img;
     }
 
-    static synchronized Image getImageFromHash(Toolkit tk,
+    static Image getImageFromHash(Toolkit tk,
                                                String filename) {
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
             security.checkRead(filename);
         }
-        Image img = (Image)imgCache.get(filename);
-        if (img == null) {
-            try {
-                img = tk.createImage(new FileImageSource(filename));
-                imgCache.put(filename, img);
-            } catch (Exception e) {
+        synchronized (imgCache) {
+            Image img = (Image)imgCache.get(filename);
+            if (img == null) {
+                try {
+                    img = tk.createImage(new FileImageSource(filename));
+                    imgCache.put(filename, img);
+                } catch (Exception e) {
+                }
             }
+            return img;
         }
-        return img;
     }
 
     public Image getImage(String filename) {