02152  Concurrent Systems - CP Lab 1: Dynamic Java Thread Creation/Cancellation - solution proposal
Technical University of Denmark DTU
02152 Concurrent Systems        Fall 2008
CP Lab 1: Dynamic Java Thread Creation/Cancellation - solution proposal
Home Plan Material  

You may find a solution proposal for steps 1-8 here: TaskControl_8.java

And still remember:

Caveat:

This purpose of this lab is to illustrate the possibility of off-loading GUI-activity to threads. Using the older AWT-GUI framework, this can be done with only minor modifications of the of the code. The reason is that the AWT-framework uses the underlying, native window components which are (assumed to be) thread-safe. This implies that concurrent threads may call update functions in the window components without risking them to be rendered inconsistently or breaking down (eg the window "freezing").

However, in the newer Swing-library, the window components are implemented all in Java, and for efficiency reasons the Swing components are not thread-safe. That means that only the event-dispatcher thread should call Swing components. By calling appropriate operations other threads may register their updates within the event queue for subsequent processing by the event-dispatcher thread.

For details of using Swing from separate threads, see the articles:

http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html
http://java.sun.com/products/jfc/tsc/articles/threads/threads3.html

PS. The same considerations apply to Windows Forms under .NET. See eg:

http://msdn2.microsoft.com/en-us/library/ms171728.aspx

Hans Henrik Løvengreen, Sep 12, 2008