![]() |
Using the Threads in Applets
PrerequisitesThis Magercise shows how to control threads in an Applet. Since an applet may not be active for all of its lifetime, such as when a user browses to a different page, its threads may need to be suspended while the applet is not active. When the applet is finally disposed (usually due to removal from the brower's cache), all of an applets suspended threads should be stopped so they can be reclaimed by Java's garbage collector.Here a Counter object is used to show a thread's activity. The thread for the Counter will be suspended when the applet is made inactive (when its stop method is called), resumed when the applet is made active again (when start is called on the applet), and stopped when the applet is destroyed. Methods for controlling threads are covered in the course notes section Controlling Thread Execution. Work LocationPerform all work for this magercise in VisualAge project MageLang Magercises, package magercises.Using the Threads in Applets. If this project does not appear in your Workspace add it from the repository (if it exists there) or create a new project using this name. Tasks
Perform the following tasks:
Add a stop method to the applet that will suspend the Counter. Add a destroy method to the applet that will stop the Counter's thread.
|
Copyright © 1996-1997 MageLang Institute. All Rights Reserved. |