The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001



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.


Can I load them in the background?

Posted by Hiran on December 02, 2001 at 12:25 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

Is it possible to draw all the images without without showing them? Because I realized that when the application is first run, it takes a while to load each image, but if I keep starting a new game (which uses the same object, and just calls a newGame method), after a while, some of the images that have already been drawn before (in previous games) show up immediately. And it looks like it doesn't matter which pile they were on in the previous game, and in the game I just started. So, I was thinking that it might be possible for me to draw all the images (as a seperate thread using a for loop) without actually displaying them on screen and then when they are called to be displayed, they should show up immediately. Would this work? If so, how would I go about doing this?


Sponsored Links

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