Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread target

 
Cathy Song
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, but if it's not, then the new thread is useless because its run() method is not overridden.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic