2626package sun .awt .image ;
2727
2828import java .util .Vector ;
29- import sun .awt .AppContext ;
3029
3130/**
3231 * An ImageFetcher is a thread used to fetch ImageFetchable objects.
3332 * Once an ImageFetchable object has been fetched, the ImageFetcher
3433 * thread may also be used to animate it if necessary, via the
3534 * startingAnimation() / stoppingAnimation() methods.
3635 *
37- * There can be up to FetcherInfo.MAX_NUM_FETCHERS_PER_APPCONTEXT
38- * ImageFetcher threads for each AppContext. A per-AppContext queue
39- * of ImageFetchables is used to track objects to fetch.
40- *
4136 * @author Jim Graham
4237 * @author Fred Ecks
4338 */
@@ -153,7 +148,6 @@ private static ImageFetchable nextImage() {
153148 info .numWaiting ++;
154149 info .waitList .wait (end - now );
155150 } catch (InterruptedException e ) {
156- // A normal occurrence as an AppContext is disposed
157151 return null ;
158152 } finally {
159153 info .numWaiting --;
@@ -280,28 +274,20 @@ private static void createFetchers(final FetcherInfo info) {
280274 // We need to instantiate a new ImageFetcher thread.
281275 // First, figure out which ThreadGroup we'll put the
282276 // new ImageFetcher into
283- final AppContext appContext = AppContext .getAppContext ();
284- ThreadGroup threadGroup = appContext .getThreadGroup ();
285- ThreadGroup fetcherThreadGroup ;
286- if (threadGroup .getParent () != null ) {
287- // threadGroup is not the root, so we proceed
288- fetcherThreadGroup = threadGroup ;
289- } else {
290- // threadGroup is the root ("system") ThreadGroup.
291- // We instead want to use its child: the "main"
292- // ThreadGroup. Thus, we start with the current
293- // ThreadGroup, and go up the tree until
294- // threadGroup.getParent().getParent() == null.
295- threadGroup = Thread .currentThread ().getThreadGroup ();
296- ThreadGroup parent = threadGroup .getParent ();
297- while ((parent != null )
298- && (parent .getParent () != null )) {
299- threadGroup = parent ;
300- parent = threadGroup .getParent ();
301- }
302- fetcherThreadGroup = threadGroup ;
277+ // We don't want the root ("system") ThreadGroup.
278+ // We instead want to use its child: the "main"
279+ // ThreadGroup. Thus, we start with the current
280+ // ThreadGroup, and go up the tree until
281+ // threadGroup.getParent().getParent() == null.
282+ ThreadGroup threadGroup = Thread .currentThread ().getThreadGroup ();
283+ ThreadGroup parent = threadGroup .getParent ();
284+ while ((parent != null )
285+ && (parent .getParent () != null )) {
286+ threadGroup = parent ;
287+ parent = threadGroup .getParent ();
303288 }
304- final ThreadGroup fetcherGroup = fetcherThreadGroup ;
289+ final ThreadGroup fetcherGroup = threadGroup ;
290+
305291
306292 for (int i = 0 ; i < info .fetchers .length ; i ++) {
307293 if (info .fetchers [i ] == null ) {
@@ -320,38 +306,27 @@ private static void createFetchers(final FetcherInfo info) {
320306}
321307
322308/**
323- * The FetcherInfo class encapsulates the per-AppContext ImageFetcher
309+ * The FetcherInfo class encapsulates the ImageFetcher
324310 * information. This includes the array of ImageFetchers, as well as
325311 * the queue of ImageFetchable objects.
326312 */
327313class FetcherInfo {
328- static final int MAX_NUM_FETCHERS_PER_APPCONTEXT = 4 ;
314+ static final int MAX_NUM_FETCHERS = 4 ;
315+ static final FetcherInfo FETCHER_INFO = new FetcherInfo ();
329316
330317 Thread [] fetchers ;
331318 int numFetchers ;
332319 int numWaiting ;
333320 Vector <ImageFetchable > waitList ;
334321
335322 private FetcherInfo () {
336- fetchers = new Thread [MAX_NUM_FETCHERS_PER_APPCONTEXT ];
323+ fetchers = new Thread [MAX_NUM_FETCHERS ];
337324 numFetchers = 0 ;
338325 numWaiting = 0 ;
339326 waitList = new Vector <>();
340327 }
341328
342- /* The key to put()/get() the FetcherInfo into/from the AppContext. */
343- private static final Object FETCHER_INFO_KEY =
344- new StringBuffer ("FetcherInfo" );
345-
346329 static FetcherInfo getFetcherInfo () {
347- AppContext appContext = AppContext .getAppContext ();
348- synchronized (appContext ) {
349- FetcherInfo info = (FetcherInfo )appContext .get (FETCHER_INFO_KEY );
350- if (info == null ) {
351- info = new FetcherInfo ();
352- appContext .put (FETCHER_INFO_KEY , info );
353- }
354- return info ;
355- }
330+ return FETCHER_INFO ;
356331 }
357332}
0 commit comments