| Author |
Thread target
|
Cathy Song
Ranch Hand
Joined: Aug 24, 2003
Posts: 270
|
|
From the code above I conclude that "For an object to be a target for a Thread, that object can be of type Thread / Runnable" Am I correct? Thanks. [ November 04, 2003: Message edited by: Cathy Song ]
|
 |
Vad Fogel
Ranch Hand
Joined: Aug 25, 2003
Posts: 504
|
|
Yes. It must be either a subclass of Thread, or implement Runnable, or be both. Thread API:
There are two ways to create a new thread of execution. One is to declare a class to be a subclass of Thread. This subclass should override the run method of class Thread. An instance of the subclass can then be allocated and started. The other way to create a thread is to declare a class that implements the Runnable interface. That class then implements the run method. An instance of the class can then be allocated, passed as an argument when creating Thread, and started.
|
 |
Cathy Song
Ranch Hand
Joined: Aug 24, 2003
Posts: 270
|
|
Hi Vad, Actually the target does not even have to be a subclass of Thread. Thread a = new Thread(); Thread b = new Thread (a); The works just fine. Thanks.
|
 |
Vad Fogel
Ranch Hand
Joined: Aug 25, 2003
Posts: 504
|
|
|
Right, but if it's not, then the new thread is useless because its run() method is not overridden.
|
 |
 |
|
|
subject: Thread target
|
|
|