Java Reference
In-Depth Information
This example gets the long-running task out of the event thread in a “fire and forget” manner,
which is probably not very useful. There is usually some sort of visual feedback when a long-
running task completes. But you cannot access presentation objects from the background
thread, so on completion the task must submit another task to run in the event thread to update
the user interface.
Listing 9.4. Binding a Long-running Task to a Visual Component.
Listing 9.5 illustrates the obvious way to do this, which is starting to get complicated; we're
now up to three layers of inner classes. The action listener first dims the button and sets a
label indicating that a computation is in progress, then submits a task to the background ex-
ecutor. When that task finishes, it queues another task to run in the event thread, which reen-
ables the button and restores the label text.
Search WWH ::




Custom Search