Please enable JavaScript.
Coggle requires JavaScript to display documents.
9.3 Long-running GUI Tasks - Coggle Diagram
9.3 Long-running GUI Tasks
Need for Background Threads
Examples:
Spell checking
Background compilation
Fetching remote resources
These must run in separate threads to keep GUI responsive
Threading in Swing
Swing makes it easy to run tasks in the event thread
No built-in support (pre-Java 6) for background execution
Solution: Create a custom Executor
Cached thread pool is a good fit
GUI rarely starts many long tasks, so low risk of resource overuse
Cancellation
Long tasks may need to be cancelled by users
Two options:
Use thread interruption (manual)
Use Future (preferred, simplifies cancellation)
Progress and Completion Indication
FutureTask offers a done hook
Triggered when task completes
Enables completion notification
SwingWorker
Purpose-built for Swing GUI background tasks
Features:
Cancellation
Completion notification
Progress indication
Available in Java 6 and later