JDK-6858206 : ImageFetcher possibly causes hang-up in the existing Jdks(7/6/5)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2009-07-08
  • Updated: 2011-02-03
  • Resolved: 2011-02-03
Related Reports
Duplicate :  
Description
ImageFetcher might cause hang-up.
This hang-up is caused from that java.awt.MediaTracker#waitForAll() keeps waiting and is not resumed.

The source code portion of ImageFetcher is as follows.
(max. num. of ImageFetcher(info.fetchers.length) is 4.)

--- ./j2se/src/share/classes/sun/awt/image/ImageFetcher.java ---
...
    public void run() {
        final FetcherInfo info = FetcherInfo.getFetcherInfo();
        try {
            fetchloop();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // (*1)
            synchronized(info.waitList) {
                Thread me = Thread.currentThread();
                for (int i = 0; i < info.fetchers.length; i++) {
                    if (info.fetchers[i] == me) {
                        info.fetchers[i] = null;
                        info.numFetchers--;
                    }
                }
            }
        }
    }
----

Assume that 4 ImageFetchers arrive at (*1).
If another thread tries to add a target Image which will be fetched,
ImageFetcher#add() is called.

--- ./j2se/src/share/classes/sun/awt/image/ImageFetcher.java ---
....
    public static void add(ImageFetchable src) {
        final FetcherInfo info = FetcherInfo.getFetcherInfo();
        synchronized(info.waitList) { // (*2)
            if (!info.waitList.contains(src)) {
                info.waitList.addElement(src);  // (*5)
                if (info.numWaiting == 0 &&
                            info.numFetchers < info.fetchers.length) { // (*3)
                    createFetchers(info); // (*4)
                }
                info.waitList.notify();
            }%)
        }
    }
....
---

The thread enters into the synchronized block at (*2),
the status between info.numFetchers and info.fetchers.lengthat
at the line of (*3) is as follows.

  info.numFetchers == info.fetchers.length

So, the thread of (*4) is not called and new ImageFetcher will not be created.

After that, all the threads which are waiting at (*1) enter into synchronized block and  all the ImageFetcher terminate. Then there is no thread which fetches the Image which is added to waitList at (*5).
As a result, MediaTracker#waitForAll() which tracks the Image added at (*5) is waiting permanently.

Comments
EVALUATION CR 6818960 reports same problem.
03-02-2011