File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread target Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread target" Watch "Thread target" New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread target