This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "threads" Watch "threads" New topic
Author

threads

manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325
I am playing around with Threads.
I understand that, we can create threads by two methods
1. by Extending Thread class
2. Implementing Runnable.
But, I just want to know, when to which method? I tried to find out in some books, I am referring and JLS also... But, Could not get any clear idea about about choosing the right method..
Can anyone plz exaplain...
thanks


MT
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
It is easier extending Thread than implementing Runnable and then creating a new Thread. Thus use the first method whenever possible. That is whenever your class is already extending of another you can't go for the first method.


SCJP2. Please Indent your code using UBB Code
Alan Chong
Ranch Hand

Joined: Jun 05, 2002
Posts: 106
Hi Murthy,
There is only one way to create thread. That is
by creating a Thread object ( or its subclass ).
Even if you use a Runnable object you still need
a Thread object. In this case you delegate what
should done in Thread's run() method to the run()
method of that Runnable object. This achieves some flexibility ( A thread's executing code doesn't have to be inside a Thread's object but can be anywhere else! )
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
What other people think.
[ July 01, 2002: Message edited by: Anthony Villanueva ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: threads
 
Similar Threads
Threads and Synchronization,synchronized Method
join()
I neeed answers for these
threads synchronized methods
IBMmock - ThreadGroup