How to Make Your Classes Threadable

   

There are two approaches to making your classes behave as threads:

  • Extending the Thread class

  • Implementing the Runnable interface

Which approach you choose depends on your application's needs and the constraints placed on it. Giving your class the capability to run as a thread does not automatically make it run as such. When a class is called runnable, that means it has the ability to act as a separate thread, but not necessarily that it is running as a separate thread. The reason for this is that the start method that is defined in the Runnable interface must be called to start the thread running. You'll learn more about the start method later in this chapter.

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

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