Java Reference
In-Depth Information
Listing 9.8. Initiating a Long-running, Cancellable Task with BackgroundTask .
For example, you might display the contents of a remote file system using a tree control.
You wouldn't want to enumerate the entire file system before you can display the tree con-
trol—that would take too much time and memory. Instead, the tree can be lazily populated as
nodes are expanded. Enumerating even a single directory on a remote volume can take a long
time, so you may want to do the enumeration in a background task. When the background
task completes, you have to get the data into the tree model somehow. This could be done by
using a thread-safe tree model, by “pushing” the data from the background task to the event
thread by posting a task with invokeLater , or by having the event thread poll to see if the
data is available.
Search WWH ::




Custom Search