mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 03:58:21 +00:00
8376434
This commit is contained in:
parent
c69275ddfe
commit
58660a24c1
@ -26,7 +26,6 @@
|
|||||||
package sun.awt.image;
|
package sun.awt.image;
|
||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import sun.awt.AppContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An ImageFetcher is a thread used to fetch ImageFetchable objects.
|
* An ImageFetcher is a thread used to fetch ImageFetchable objects.
|
||||||
@ -34,10 +33,6 @@ import sun.awt.AppContext;
|
|||||||
* thread may also be used to animate it if necessary, via the
|
* thread may also be used to animate it if necessary, via the
|
||||||
* startingAnimation() / stoppingAnimation() methods.
|
* startingAnimation() / stoppingAnimation() methods.
|
||||||
*
|
*
|
||||||
* There can be up to FetcherInfo.MAX_NUM_FETCHERS_PER_APPCONTEXT
|
|
||||||
* ImageFetcher threads for each AppContext. A per-AppContext queue
|
|
||||||
* of ImageFetchables is used to track objects to fetch.
|
|
||||||
*
|
|
||||||
* @author Jim Graham
|
* @author Jim Graham
|
||||||
* @author Fred Ecks
|
* @author Fred Ecks
|
||||||
*/
|
*/
|
||||||
@ -153,7 +148,6 @@ class ImageFetcher extends Thread {
|
|||||||
info.numWaiting++;
|
info.numWaiting++;
|
||||||
info.waitList.wait(end - now);
|
info.waitList.wait(end - now);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// A normal occurrence as an AppContext is disposed
|
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
info.numWaiting--;
|
info.numWaiting--;
|
||||||
@ -280,28 +274,20 @@ class ImageFetcher extends Thread {
|
|||||||
// We need to instantiate a new ImageFetcher thread.
|
// We need to instantiate a new ImageFetcher thread.
|
||||||
// First, figure out which ThreadGroup we'll put the
|
// First, figure out which ThreadGroup we'll put the
|
||||||
// new ImageFetcher into
|
// new ImageFetcher into
|
||||||
final AppContext appContext = AppContext.getAppContext();
|
// We don't want the root ("system") ThreadGroup.
|
||||||
ThreadGroup threadGroup = appContext.getThreadGroup();
|
// We instead want to use its child: the "main"
|
||||||
ThreadGroup fetcherThreadGroup;
|
// ThreadGroup. Thus, we start with the current
|
||||||
if (threadGroup.getParent() != null) {
|
// ThreadGroup, and go up the tree until
|
||||||
// threadGroup is not the root, so we proceed
|
// threadGroup.getParent().getParent() == null.
|
||||||
fetcherThreadGroup = threadGroup;
|
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
|
||||||
} else {
|
ThreadGroup parent = threadGroup.getParent();
|
||||||
// threadGroup is the root ("system") ThreadGroup.
|
while ((parent != null)
|
||||||
// We instead want to use its child: the "main"
|
&& (parent.getParent() != null)) {
|
||||||
// ThreadGroup. Thus, we start with the current
|
threadGroup = parent;
|
||||||
// ThreadGroup, and go up the tree until
|
parent = threadGroup.getParent();
|
||||||
// threadGroup.getParent().getParent() == null.
|
|
||||||
threadGroup = Thread.currentThread().getThreadGroup();
|
|
||||||
ThreadGroup parent = threadGroup.getParent();
|
|
||||||
while ((parent != null)
|
|
||||||
&& (parent.getParent() != null)) {
|
|
||||||
threadGroup = parent;
|
|
||||||
parent = threadGroup.getParent();
|
|
||||||
}
|
|
||||||
fetcherThreadGroup = threadGroup;
|
|
||||||
}
|
}
|
||||||
final ThreadGroup fetcherGroup = fetcherThreadGroup;
|
final ThreadGroup fetcherGroup = threadGroup;
|
||||||
|
|
||||||
|
|
||||||
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) {
|
||||||
@ -320,12 +306,13 @@ class ImageFetcher extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The FetcherInfo class encapsulates the per-AppContext ImageFetcher
|
* The FetcherInfo class encapsulates the ImageFetcher
|
||||||
* information. This includes the array of ImageFetchers, as well as
|
* information. This includes the array of ImageFetchers, as well as
|
||||||
* the queue of ImageFetchable objects.
|
* the queue of ImageFetchable objects.
|
||||||
*/
|
*/
|
||||||
class FetcherInfo {
|
class FetcherInfo {
|
||||||
static final int MAX_NUM_FETCHERS_PER_APPCONTEXT = 4;
|
static final int MAX_NUM_FETCHERS = 4;
|
||||||
|
static final FetcherInfo FETCHER_INFO = new FetcherInfo();
|
||||||
|
|
||||||
Thread[] fetchers;
|
Thread[] fetchers;
|
||||||
int numFetchers;
|
int numFetchers;
|
||||||
@ -333,25 +320,13 @@ class FetcherInfo {
|
|||||||
Vector<ImageFetchable> waitList;
|
Vector<ImageFetchable> waitList;
|
||||||
|
|
||||||
private FetcherInfo() {
|
private FetcherInfo() {
|
||||||
fetchers = new Thread[MAX_NUM_FETCHERS_PER_APPCONTEXT];
|
fetchers = new Thread[MAX_NUM_FETCHERS];
|
||||||
numFetchers = 0;
|
numFetchers = 0;
|
||||||
numWaiting = 0;
|
numWaiting = 0;
|
||||||
waitList = new Vector<>();
|
waitList = new Vector<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The key to put()/get() the FetcherInfo into/from the AppContext. */
|
|
||||||
private static final Object FETCHER_INFO_KEY =
|
|
||||||
new StringBuffer("FetcherInfo");
|
|
||||||
|
|
||||||
static FetcherInfo getFetcherInfo() {
|
static FetcherInfo getFetcherInfo() {
|
||||||
AppContext appContext = AppContext.getAppContext();
|
return FETCHER_INFO;
|
||||||
synchronized(appContext) {
|
|
||||||
FetcherInfo info = (FetcherInfo)appContext.get(FETCHER_INFO_KEY);
|
|
||||||
if (info == null) {
|
|
||||||
info = new FetcherInfo();
|
|
||||||
appContext.put(FETCHER_INFO_KEY, info);
|
|
||||||
}
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user