JDK-4335416 : ImageIcon.loadImage() is hanging.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.3.0,1.3.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8,windows_nt
  • CPU: x86,sparc
  • Submitted: 2000-05-03
  • Updated: 2001-11-13
  • Resolved: 2001-11-13
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description

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) 
======================================================================

Comments
EVALUATION This was fixed as part of refer to it for information on the fix. scott.violet@eng 2000-11-28 It appeared so that this is a different problem as we have customers who are able to reproduce this bg using 1.3.0_01 (in which the 4332685 had been fixed) on a single CPU configuration. This will need further investigation. dmitri.trembovetski@eng 2001-01-10 This bug seems similar to 4480705: Java SWING EventQueue thread deadlocks with animated GIFs In order to confirm that I need a full stack trace (not a blocking thread only). A test case would be very useful. Marking as incomplete. ###@###.### 2001-08-22 Closing as dup of 4480705: Java SWING EventQueue thread deadlocks with animated GIFs ###@###.### 2001-11-13
22-08-2001