diff --git a/jdk/src/share/classes/sun/awt/image/ImageFetcher.java b/jdk/src/share/classes/sun/awt/image/ImageFetcher.java index 083ba79841b..5b1293fb043 100644 --- a/jdk/src/share/classes/sun/awt/image/ImageFetcher.java +++ b/jdk/src/share/classes/sun/awt/image/ImageFetcher.java @@ -61,8 +61,10 @@ class ImageFetcher extends Thread { /** * Adds an ImageFetchable to the queue of items to fetch. Instantiates * a new ImageFetcher if it's reasonable to do so. + * If there is no available fetcher to process an ImageFetchable, then + * reports failure to caller. */ - public static void add(ImageFetchable src) { + public static boolean add(ImageFetchable src) { final FetcherInfo info = FetcherInfo.getFetcherInfo(); synchronized(info.waitList) { if (!info.waitList.contains(src)) { @@ -71,9 +73,23 @@ class ImageFetcher extends Thread { info.numFetchers < info.fetchers.length) { createFetchers(info); } - info.waitList.notify(); + /* Creation of new fetcher may fail due to high vm load + * or some other reason. + * If there is already exist, but busy, fetcher, we leave + * the src in queue (it will be handled by existing + * fetcher later). + * Otherwise, we report failure: there is no fetcher + * to handle the src. + */ + if (info.numFetchers > 0) { + info.waitList.notify(); + } else { + info.waitList.removeElement(src); + return false; + } } } + return true; } /** @@ -291,11 +307,15 @@ class ImageFetcher extends Thread { public Object run() { for (int i = 0; i < info.fetchers.length; i++) { if (info.fetchers[i] == null) { - info.fetchers[i] = new ImageFetcher( + ImageFetcher f = new ImageFetcher( fetcherGroup, i); - info.fetchers[i].start(); - info.numFetchers++; - break; + try { + f.start(); + info.fetchers[i] = f; + info.numFetchers++; + break; + } catch (Error e) { + } } } return null; diff --git a/jdk/src/share/classes/sun/awt/image/InputStreamImageSource.java b/jdk/src/share/classes/sun/awt/image/InputStreamImageSource.java index e2aecb3073c..7d0b7eaf43b 100644 --- a/jdk/src/share/classes/sun/awt/image/InputStreamImageSource.java +++ b/jdk/src/share/classes/sun/awt/image/InputStreamImageSource.java @@ -164,8 +164,13 @@ public abstract class InputStreamImageSource implements ImageProducer, private synchronized void startProduction() { if (!awaitingFetch) { - ImageFetcher.add(this); - awaitingFetch = true; + if (ImageFetcher.add(this)) { + awaitingFetch = true; + } else { + ImageConsumerQueue cq = consumers; + consumers = null; + errorAllConsumers(cq, false); + } } }