The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

The Threads Thread

Posted by Matt Gerrans on December 01, 2001 at 4:51 PM

I would make a CardLoader class, which is runnable. Then for each card, instantiate an instance of this class (its constructor would be told which card) and it will start the loading. It would have isLoaded() and other such useful methods.

However, starting 53 threads (including the back, which I assume is the same for all!), is a lot. Maybe you might want to start by loading the cards that are first visible (do a "deal" even before the user chooses "deal") and then continue to load cards that are not visible in the background, but not all at once. Having so many threads running at once will probably give you worse performance than doing them serially. Bruce Eckel's book Thinking in Java, Second Edition has an example in the Threads chapter that draws rectagles on a grid. These rectangles just sit there and change their color. When there are a lot of them and each has its own color-chaning thread, the performance is pretty bad. When it is changed so that groups (like rows, for instance) share one thread, the performance is better. The moral is, threads can give you better performance when used judiciously and worse when overused.

- mfg





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us