• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

threads

 
manasa teja
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alan Chong
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What other people think.
[ July 01, 2002: Message edited by: Anthony Villanueva ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic