081105slides_handouts

081105slides_handouts - 1 UVa CS205 Engineering Software...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 UVa CS205 Engineering Software 081105 Concurrency in GUIs UVa CS205 Engineering Software 081105 Conflicting Needs Limit concurrency Use concurrency Avoid deadlock Avoid freezing UVa CS205 Engineering Software 081105 Avoiding Trouble ¡ Freezing ¢ GUIs can stop working for an unacceptable duration when a GUI event is resource intensive ¡ e.g. network or disk I/O, expensive computation… ¡ Event processing needs to be handed to another thread. ¡ Deadlock ¢ GUI toolkit designers say deadlock avoidance is very hard, even if you’re smart. ¡ Event processing code tends to acquire locks bottom-up, which creates problems. UVa CS205 Engineering Software 081105 Swing’s Approach ¡ Avoid concurrency for most tasks ¢ Use single thread, the EDT ¡ Hand off time-consuming tasks to special worker threads ¢ Provided by Swing ¢ Regulated to minimize trouble 2 UVa CS205 Engineering Software 081105 Threads in Swing ¡ Swing thread types: ¢ Initial threads (start program) ¢ One event dispatch thread –EDT - (all event- handling code) ¢ Worker threads (do time-consuming tasks in background) Swing framework does most of the work – programmer doesn’t need to create threads UVa CS205 Engineering Software 081105 Threads and GUIs ¡ Initial thread - each application has one - it invokes main() ¡ Event dispatch thread (EDT) – you should invoke any GUI you write using the EDT ¢ reason - swing methods are not "thread-safe" - invoking them from multiple threads will cause interference ¢ set up GUI and then respond to events ¢ Use for short tasks - if long, unresponsive to user ¡ Worker threads ¢ for long tasks ¢ each is an instance of javax.swing.SwingWorker ¢ methods for swingWorker enforce thread safety UVa CS205 Engineering Software 081105 Event Dispatch Thread ¡ Special thread ¢ Created by AWT library ¢ Inherited by Swing...
View Full Document

This note was uploaded on 04/05/2010 for the course CS 150 taught by Professor Humphreys,g during the Spring '08 term at UVA.

Page1 / 5

081105slides_handouts - 1 UVa CS205 Engineering Software...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online