Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
For an online project, downloading two megabytes of data is likely
to be a problem. In its current iteration, the program will stop until
all data has been downloaded. A better alternative is to use the
built-in Thread class to load the
data asynchronously. The thread acts independently of the rest of the
program, gradually adding locations by incrementing placeCount. When placeCount and totalCount are identical, the data has
finished loading.
A thread provides a way to bundle a function
in your program so that it can run at the same time as another part of
the program. In this case, rather than waiting for the data to download,
a thread can be used for the download while the main draw( ) method of the program continues to
run. Because the program is still running, it remains responsive to user
input, which makes it feel faster than if the program halted until the
download was finished.