| ||||
Copyright 1999 Sams Publishing |
|
Summary |
In this chapter, I showed you a technique for creating active classes that are self-running. Self-running classes automatically create an internal thread that runs inside the object. This thread is usually started in the constructor, but can be started later if necessary. Users of self-running objects do not need to concern themselves with the details of creating and starting a thread for an objectin fact, they dont even need to know that a thread is running inside it at all. Additionally, because the users of a self-running object do not have a reference to the internal thread, they cannot erroneously use deprecated methods to suspend or stop the thread at a bad time. |
Of the two self-running designs presented, I recommend that you use the one that hides run() within an anonymous, inner class. This design has the advantage of preventing a user from mistakenly invoking run() directly, or from mistakenly creating a new thread that invokes run() . |
| |||
Toc |