Using getParent()

Chapter 11 - Self-Running Objects

Java Thread Programming
Paul Hyde
  Copyright 1999 Sams Publishing

Chapter 11: Self-Running Objects
Overview
In an object-based application, most objects are passive . A passive object just sits there waiting for one of its methods to be invoked. A passive objects private member variables can only be changed by the code in its own methods, so its state remains constant until one of its methods is invoked. In a multithreaded environment like Java, threads can run within objects to make the objects active . Objects that are active make autonomous changes to themselves .
Sometimes in modeling a system, it becomes apparent that if some of the objects were active, the model would be simplified. Earlier in this book, classes that implemented Runnable were instantiated , passed to one of the constructors of Thread , and then start() was invoked. This style required a user of a class to know that a thread needed to be started to run within it, creating a burden on the user of the class. In addition, because the user of the class created the Thread object for it, a reference to Thread was available for misuse. The user of the class could erroneously set the priority of the thread, suspend it at a bad time, or outright stop the thread when the object it was running in was in an inconsistent state. Having to activate objects externally is both inconvenient and potentially hazardous. In this chapter, Ill show you how to have an active object transparently create and start up its own internal thread.

Toc


Java Thread Programming
Java Thread Programming
ISBN: 0672315858
EAN: 2147483647
Year: 2005
Pages: 149
Authors: Paul Hyde

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net