6818960: ImageFetcher ( MediaTracker) Thread leak

Reviewed-by: igor, prr
This commit is contained in:
Andrew Brygin 2011-02-09 22:24:42 +03:00
parent a6241f31b1
commit 763f890029
2 changed files with 33 additions and 8 deletions

View File

@ -61,8 +61,10 @@ class ImageFetcher extends Thread {
/** /**
* Adds an ImageFetchable to the queue of items to fetch. Instantiates * Adds an ImageFetchable to the queue of items to fetch. Instantiates
* a new ImageFetcher if it's reasonable to do so. * 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(); final FetcherInfo info = FetcherInfo.getFetcherInfo();
synchronized(info.waitList) { synchronized(info.waitList) {
if (!info.waitList.contains(src)) { if (!info.waitList.contains(src)) {
@ -71,9 +73,23 @@ class ImageFetcher extends Thread {
info.numFetchers < info.fetchers.length) { info.numFetchers < info.fetchers.length) {
createFetchers(info); 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() { public Object run() {
for (int i = 0; i < info.fetchers.length; i++) { for (int i = 0; i < info.fetchers.length; i++) {
if (info.fetchers[i] == null) { if (info.fetchers[i] == null) {
info.fetchers[i] = new ImageFetcher( ImageFetcher f = new ImageFetcher(
fetcherGroup, i); fetcherGroup, i);
info.fetchers[i].start(); try {
info.numFetchers++; f.start();
break; info.fetchers[i] = f;
info.numFetchers++;
break;
} catch (Error e) {
}
} }
} }
return null; return null;

View File

@ -164,8 +164,13 @@ public abstract class InputStreamImageSource implements ImageProducer,
private synchronized void startProduction() { private synchronized void startProduction() {
if (!awaitingFetch) { if (!awaitingFetch) {
ImageFetcher.add(this); if (ImageFetcher.add(this)) {
awaitingFetch = true; awaitingFetch = true;
} else {
ImageConsumerQueue cq = consumers;
consumers = null;
errorAllConsumers(cq, false);
}
} }
} }