6818960: ImageFetcher ( MediaTracker) Thread leak
Reviewed-by: igor, prr
This commit is contained in:
parent
a6241f31b1
commit
763f890029
@ -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,10 +73,24 @@ class ImageFetcher extends Thread {
|
||||
info.numFetchers < info.fetchers.length) {
|
||||
createFetchers(info);
|
||||
}
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an ImageFetchable from the queue of items to fetch.
|
||||
@ -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();
|
||||
try {
|
||||
f.start();
|
||||
info.fetchers[i] = f;
|
||||
info.numFetchers++;
|
||||
break;
|
||||
} catch (Error e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -164,8 +164,13 @@ public abstract class InputStreamImageSource implements ImageProducer,
|
||||
|
||||
private synchronized void startProduction() {
|
||||
if (!awaitingFetch) {
|
||||
ImageFetcher.add(this);
|
||||
if (ImageFetcher.add(this)) {
|
||||
awaitingFetch = true;
|
||||
} else {
|
||||
ImageConsumerQueue cq = consumers;
|
||||
consumers = null;
|
||||
errorAllConsumers(cq, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user