-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.3.0, 1.3.1
-
x86, sparc
-
solaris_8, windows_nt
Name: stC104175 Date: 05/03/2000
java version "1.3.0rc2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc2-Y)
Java HotSpot(TM) Client VM (build 1.3.0rc2-Y, mixed mode)
ImageIcon.loadImage() is hanging intermittently. Here is the jdk 1.3 source for
the method.
protected void loadImage(Image image) {
synchronized(tracker) {
tracker.addImage(image, 0);
try {
tracker.waitForID(0, 0);
} catch (InterruptedException e) {
System.out.println("INTERRUPTED while loading Image");
}
loadStatus = tracker.statusID(0, false);
tracker.removeImage(image, 0);
width = image.getWidth(imageObserver);
height = image.getHeight(imageObserver);
}
}
Tracker.waitForID(0, 0) never returns. It hangs at MediaTracker line 401
waitForID(0,0)
public synchronized boolean waitForID(int id, long ms)
throws InterruptedException
{
long end = System.currentTimeMillis() + ms;
boolean first = true;
while (true) {
int status = statusID(id, first, first);
if ((status & LOADING) == 0) {
return (status == COMPLETE);
}
first = false;
long timeout;
if (ms == 0) {
timeout = 0;
} else {
timeout = end - System.currentTimeMillis();
if (timeout <= 0) {
return false;
}
}
wait(timeout);
}
}
Hangs at wait(timeout). Timeout is 0. Can you guarantee that the thread will be
notified in all possible cases? Apparently not, because It waits and is never
notified. The whole app then freezes. :(
In the jdk 1.2.2 version of ImageIcon. Which works fine. LoadImage is
/**
* Wait for the image to load
*/
protected void loadImage(Image image) {
synchronized(tracker) {
tracker.addImage(image, 0);
try {
tracker.waitForID(0, 5000);
} catch (InterruptedException e) {
System.out.println("INTERRUPTED while loading Image");
}
loadStatus = tracker.statusID(0, false);
tracker.removeImage(image, 0);
width = image.getWidth(imageObserver);
height = image.getHeight(imageObserver);
}
}
Notice
" tracker.waitForID(0, 5000);"
The thread only waits 5 seconds at the end of MediaTracker.waitForID() before
looping again. I think this was by design, because there is no guarantee the
thread will be notified if it enters into an infinite wait. The change in wait
times is apparently causing serious threading issues.
For related bugs See bug reports 4226683, 4272382.
(Review ID: 104414)
======================================================================
- duplicates
-
JDK-4411985 The swing component does not get printed
-
- Closed
-
-
JDK-4480705 Java SWING EventQueue thread deadlocks with animated GIFs
-
- Resolved
-
- relates to
-
JDK-4332685 AbstractButton.getDisabledIcon can cause the VM to hang! (dual-processor box)
-
- Closed
-