6903354: deadlock involving Component.show & SunToolkit.getImageFromHash

Reviewed-by: art, bae
This commit is contained in:
Anton Tarasov 2009-12-04 15:07:15 +03:00
parent b0a13700e1
commit 7eb100548d

View File

@ -800,9 +800,9 @@ public abstract class SunToolkit extends Toolkit
} }
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(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
try { try {
@ -830,32 +830,36 @@ public abstract class SunToolkit extends Toolkit
sm.checkConnect(url.getHost(), url.getPort()); sm.checkConnect(url.getHost(), url.getPort());
} }
} }
Image img = (Image)imgCache.get(url); synchronized (imgCache) {
if (img == null) { Image img = (Image)imgCache.get(url);
try { if (img == null) {
img = tk.createImage(new URLImageSource(url)); try {
imgCache.put(url, img); img = tk.createImage(new URLImageSource(url));
} catch (Exception e) { imgCache.put(url, img);
} catch (Exception e) {
}
} }
return img;
} }
return img;
} }
static synchronized Image getImageFromHash(Toolkit tk, static Image getImageFromHash(Toolkit tk,
String filename) { String filename) {
SecurityManager security = System.getSecurityManager(); SecurityManager security = System.getSecurityManager();
if (security != null) { if (security != null) {
security.checkRead(filename); security.checkRead(filename);
} }
Image img = (Image)imgCache.get(filename); synchronized (imgCache) {
if (img == null) { Image img = (Image)imgCache.get(filename);
try { if (img == null) {
img = tk.createImage(new FileImageSource(filename)); try {
imgCache.put(filename, img); img = tk.createImage(new FileImageSource(filename));
} catch (Exception e) { imgCache.put(filename, img);
} catch (Exception e) {
}
} }
return img;
} }
return img;
} }
public Image getImage(String filename) { public Image getImage(String filename) {